
#include "ctc_const.h"
#include "ctc_error.h"
#include "ctc_common.h"
#include "ctc_packet.h"

#include "sys_usw_common.h"
#include "sys_usw_nexthop_api.h"
#include "sys_usw_nexthop_hw.h"
#include "sys_usw_nexthop.h"
#include "sys_usw_qos_api.h"
#include "sys_usw_ftm.h"

#include "drv_api.h"


typedef int32 (*sys_usw_nh_fun)(uint8, void*, void*, uint32*);
typedef int32 (*sys_usw_nh_fun_unmap)(uint8, void*, void*);
typedef int32 (*sys_usw_nh_update)(uint8, void*);

#define SYS_L3EDITRW_MODE_DEST 1    /*From TMM, use l4Port0 or ipAddr0*/
#define SYS_L3EDITRW_MODE_SRC  2    /*From TMM, use l4Port1 or ipAddr1*/
#define SYS_L3EDITRW_MODE_SWAP 3    /*From TMM*/

#define SYS_L4CHKSUM_DISABLE_UPDATE_FOR_SRV6 7
#define SYS_L4CHKSUM_ENABLE_UPDATE_FOR_SRV6 6
int32
sys_usw_nh_map_dsfwd(uint8 lchip, sys_fwd_t* p_sys_fwd, void *p_ds, uint32* p_offset)
{
    DsFwdHalf_m dsfwd_half;
    if (p_sys_fwd->is_6w)
    {
        SetDsFwd(V, forceBackEn_f,         p_ds,   p_sys_fwd->force_back_en);
        SetDsFwd(V, bypassIngressEdit_f,   p_ds,   p_sys_fwd->bypass_igs_edit);
        SetDsFwd(V, lengthAdjustType_f,    p_ds,   p_sys_fwd->adjust_len_idx);
        SetDsFwd(V, apsBridgeEn_f,         p_ds,   p_sys_fwd->aps_bridge_en);
        SetDsFwd(V, destMap_f,             p_ds,   p_sys_fwd->dest_map);
        SetDsFwd(V, nextHopPtr_f,          p_ds,   p_sys_fwd->nexthop_ptr);
        SetDsFwd(V, nextHopExt_f,          p_ds,   p_sys_fwd->nexthop_ext);
        SetDsFwd(V, isHalf_f,              p_ds,   0);
        SetDsFwd(V, truncateLenProfId_f,   p_ds,   p_sys_fwd->truncate_profile);
        SetDsFwd(V, truncateLenProfIdType_f,   p_ds,   0);
        SetDsFwd(V, statsPtr_f,            p_ds,   0);
        SetDsFwd(V, sendLocalPhyPort_f,    p_ds,   0);
        SetDsFwd(V, cloudSecEn_f,          p_ds,   p_sys_fwd->cloud_sec_en);
        SetDsFwd(V, editAuxDataEn_f,          p_ds,   0);
        SetDsFwd(V, logicDestPort_f,          p_ds,   p_sys_fwd->logic_port);
        SetDsFwd(V, portIsolationGroupId_f,   p_ds,   0);
        if (p_sys_fwd->is_ecmp)
        {
            SetDsFwd(V, ecmpGroupId_f,              p_ds,   p_sys_fwd->ecmp_gid);
        }

        if (p_sys_fwd->logic_port)
        {
            SetDsFwd(V, ecmpTunnelMode_f, p_ds, 1);
        }
    }
    else
    {
        CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip,
                                                   p_sys_fwd->is_dsfwd1? SYS_NH_ENTRY_TYPE_FWD1 : SYS_NH_ENTRY_TYPE_FWD,
                                                   p_sys_fwd->offset, p_ds));

        sal_memset(&dsfwd_half, 0, sizeof(DsFwdHalf_m));
        SetDsFwdHalf(V, bypassIngressEdit_f,   &dsfwd_half,   p_sys_fwd->bypass_igs_edit);
        SetDsFwdHalf(V, lengthAdjustType_f,    &dsfwd_half,   p_sys_fwd->adjust_len_idx);
        SetDsFwdHalf(V, apsBridgeEn_f,         &dsfwd_half,   p_sys_fwd->aps_bridge_en);
        SetDsFwdHalf(V, destMap_f,             &dsfwd_half,   p_sys_fwd->dest_map);
        SetDsFwdHalf(V, nextHopPtr_f,          &dsfwd_half,   p_sys_fwd->nexthop_ptr);
        SetDsFwdHalf(V, isHalf_f,              &dsfwd_half,   1);
        SetDsFwdHalf(V, nextHopExt_f,          &dsfwd_half,   p_sys_fwd->nexthop_ext);
        SetDsFwdHalf(V, cloudSecEn_f,          &dsfwd_half,   p_sys_fwd->cloud_sec_en);

        /*PacketInfo.editAuxData(15,0) = (IpeFwdCtl.editAuxDataHighBits(1,0),DsFwdTemp.sendLocalPhyPort,FormatDsFwd.apsBridgeEn,DsFwdTemp.ecmpGroupId(11,0));*/
        if (p_sys_fwd->logic_port_ext)
        {
            uint16 logic_port_ext = p_sys_fwd->logic_port_ext - MCHIP_CAP(SYS_CAP_NH_LOGIC_DEST_PORT_EXT_BASE);
            SetDsFwdHalf(V, ecmpTunnelMode_f, &dsfwd_half, 1);
            SetDsFwdHalf(V, sendLocalPhyPort_f, &dsfwd_half, ((logic_port_ext >> 13) & 0x1));
            SetDsFwdHalf(V, apsBridgeEn_f, &dsfwd_half, ((logic_port_ext >> 12) & 0x1));
            SetDsFwdHalf(V, ecmpGroupId_f, &dsfwd_half, logic_port_ext & 0xFFF);
        }

        if (p_sys_fwd->offset % 2 == 0)
        {
            SetDsFwdDualHalf(A, g_0_dsFwdHalf_f,   p_ds,   &dsfwd_half);
        }
        else
        {
            SetDsFwdDualHalf(A, g_1_dsFwdHalf_f,   p_ds,   &dsfwd_half);
        }

    }
    *p_offset = *p_offset / 2; /*dwfwd have two member*/
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_dsfwd(uint8 lchip, sys_fwd_t* p_sys_fwd, void *p_ds)
{
    DsFwdHalf_m dsfwd_half;

    p_sys_fwd->is_6w = !GetDsFwd(V, isHalf_f,p_ds);
    if (p_sys_fwd->is_6w)
    {
        p_sys_fwd->force_back_en = GetDsFwd(V, forceBackEn_f, p_ds);
        p_sys_fwd->bypass_igs_edit = GetDsFwd(V, bypassIngressEdit_f, p_ds);
        p_sys_fwd->adjust_len_idx = GetDsFwd(V, lengthAdjustType_f, p_ds);
        p_sys_fwd->aps_bridge_en = GetDsFwd(V, apsBridgeEn_f, p_ds);
        p_sys_fwd->dest_map = GetDsFwd(V, destMap_f, p_ds);
        p_sys_fwd->nexthop_ptr = GetDsFwd(V, nextHopPtr_f, p_ds);
        p_sys_fwd->nexthop_ext = GetDsFwd(V, nextHopExt_f, p_ds);
        p_sys_fwd->truncate_profile = GetDsFwd(V, truncateLenProfId_f, p_ds);
        p_sys_fwd->cloud_sec_en = GetDsFwd(V, cloudSecEn_f, p_ds);
        p_sys_fwd->logic_port = GetDsFwd(V, logicDestPort_f, p_ds);
        p_sys_fwd->ecmp_gid = GetDsFwd(V, ecmpGroupId_f, p_ds);
        p_sys_fwd->is_ecmp = !!p_sys_fwd->ecmp_gid;
    }
    else
    {
        sal_memset(&dsfwd_half, 0, sizeof(DsFwdHalf_m));
        if (p_sys_fwd->offset % 2 == 0)
        {
            GetDsFwdDualHalf(A, g_0_dsFwdHalf_f, p_ds, &dsfwd_half);
        }
        else
        {
            GetDsFwdDualHalf(A, g_1_dsFwdHalf_f, p_ds, &dsfwd_half);
        }
        p_sys_fwd->bypass_igs_edit = GetDsFwdHalf(V, bypassIngressEdit_f, &dsfwd_half);
        p_sys_fwd->adjust_len_idx = GetDsFwdHalf(V, lengthAdjustType_f, &dsfwd_half);
        p_sys_fwd->aps_bridge_en = GetDsFwdHalf(V, apsBridgeEn_f, &dsfwd_half);
        p_sys_fwd->dest_map = GetDsFwdHalf(V, destMap_f, &dsfwd_half);
        p_sys_fwd->nexthop_ptr = GetDsFwdHalf(V, nextHopPtr_f, &dsfwd_half);
        p_sys_fwd->nexthop_ext = GetDsFwdHalf(V, nextHopExt_f, &dsfwd_half);
        p_sys_fwd->cloud_sec_en = GetDsFwdHalf(V, cloudSecEn_f, &dsfwd_half);
        if (GetDsFwdHalf(V, ecmpTunnelMode_f, &dsfwd_half))
        {
            p_sys_fwd->logic_port_ext = GetDsFwdHalf(V, ecmpGroupId_f, &dsfwd_half) | (p_sys_fwd->aps_bridge_en<<12)|(GetDsFwdHalf(V, sendLocalPhyPort_f, &dsfwd_half)<<13);
            p_sys_fwd->logic_port_ext+= MCHIP_CAP(SYS_CAP_NH_LOGIC_DEST_PORT_EXT_BASE);
        }
    }


    return CTC_E_NONE;
}

int32
sys_usw_nh_update_fwd(uint8 lchip, sys_fwd_t* p_sys_fwd)
{
    DsFwd_m dsfwd;
    DsFwdHalf_m dsfwd_half;

    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_FWD, p_sys_fwd->offset, &dsfwd));

    if (p_sys_fwd->is_6w)
    {
        if (p_sys_fwd->update_type == SYS_NH_UPDATE_TYPE_LDP)
        {
            SetDsFwd(V, logicDestPort_f,             &dsfwd,   p_sys_fwd->logic_port);
        }
    }
    else
    {
        if (p_sys_fwd->offset % 2 == 0)
        {
            GetDsFwdDualHalf(A, g_0_dsFwdHalf_f,   &dsfwd,   &dsfwd_half);
        }
        else
        {
            GetDsFwdDualHalf(A, g_1_dsFwdHalf_f,   &dsfwd,   &dsfwd_half);
        }

        if (p_sys_fwd->update_type == 1)
        {
            SetDsFwdHalf(V, destMap_f,             &dsfwd_half,   p_sys_fwd->dest_map);
        }


        if (p_sys_fwd->offset % 2 == 0)
        {
            SetDsFwdDualHalf(A, g_0_dsFwdHalf_f,   &dsfwd,   &dsfwd_half);
        }
        else
        {
            SetDsFwdDualHalf(A, g_1_dsFwdHalf_f,   &dsfwd,   &dsfwd_half);
        }

    }

    CTC_ERROR_RETURN(sys_usw_nh_set_asic_table(lchip, SYS_NH_ENTRY_TYPE_FWD, p_sys_fwd->offset, &dsfwd));

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_dsnexthop(uint8 lchip, sys_nexthop_t* p_sys_dsnh, void *p_ds, uint32* p_offset)
{
    uint32 offset = 0;
    hw_mac_addr_t mac_da;
    uint32 stats_ptr = 0;
    uint8 do_vlan_edit = 0;
    uint8 stats_low_bits = 0;
    uint8 ctag_mode = 0;
    uint8 is_4w_cid = 0;

    /*----------mapping dsnexthop4w---------------*/
    stats_low_bits = DRV_IS_DUET2(lchip)?9:10;

    if (( (p_sys_dsnh->offset >> SYS_NH_DSNH_INTERNAL_SHIFT) == SYS_NH_DSNH_INTERNAL_BASE) &&
            (p_sys_dsnh->offset & 0xF) == SYS_DSNH4WREG_INDEX_FOR_BRG)
    {
        SetDsNextHop4W(V, statsType_f, p_ds,   0);
    }
    else
    {
        SetDsNextHop4W(V, statsType_f, p_ds,   1);
        if (!DRV_IS_DUET2(lchip) && g_usw_nh_master[lchip]->bpe_en)
        {
            p_sys_dsnh->stats_ptr |=  (1<<15);
        }
    }

    if (p_sys_dsnh->ecid_valid)
    {
        p_sys_dsnh->stats_ptr = ((1 << 14) | (p_sys_dsnh->ecid&0x3FFF));
    }


    SetDsNextHop4W(V, isNexthop8W_f,        p_ds,   p_sys_dsnh->is_nexthop8_w);
    SetDsNextHop4W(V, shareType_f,          p_ds,   p_sys_dsnh->share_type);
    SetDsNextHop4W(V, apsBridgeEn_f,        p_ds,   p_sys_dsnh->aps_bridge_en);
    SetDsNextHop4W(V, payloadOperation_f,   p_ds,   p_sys_dsnh->payload_operation);
    SetDsNextHop4W(V, destVlanPtr_f,        p_ds,   p_sys_dsnh->dest_vlan_ptr);
    SetDsNextHop4W(V, isLeaf_f,             p_ds,   p_sys_dsnh->is_leaf);
    SetDsNextHop4W(V, mtuCheckEn_f,         p_ds,   p_sys_dsnh->mtu_check_en);
    SetDsNextHop4W(V, svlanTagged_f,        p_ds,   p_sys_dsnh->svlan_tagged);
    SetDsNextHop4W(V, vlanXlateMode_f,      p_ds,   p_sys_dsnh->vlan_xlate_mode);
    SetDsNextHop4W(V, stripL2Hdr_f,      p_ds,   p_sys_dsnh->strip_l2_hdr);
    SetDsNextHop4W(V, stripHdrMode_f,      p_ds,   p_sys_dsnh->strip_l2_hdr);/*AT*/
    SetDsNextHop4W(V, destVlanPtrDeriveMode_f,      p_ds,   p_sys_dsnh->destVlanPtrDeriveMode);
    SetDsNextHop4W(V, useTtlFromPacket_f,   p_ds,   p_sys_dsnh->use_packet_ttl);
    SetDsNextHop4W(V, skipPopDvpTbl_f,      p_ds,   p_sys_dsnh->dvp_tbl_valid?0:1);
    SetDsNextHop4W(V, xAluEn_f,      p_ds,   p_sys_dsnh->srv6_aps_en);

    if(SYS_NH_OP_BRIDGE_INNER == p_sys_dsnh->payload_operation || SYS_NH_OP_BRIDGE_VPLS == p_sys_dsnh->payload_operation || p_sys_dsnh->bridge_inner)
    {
        SetDsNextHop4W(V, bridgeInner_f,    p_ds,   1); /* for TMM*/
        if(DRV_IS_AT(lchip) && g_usw_nh_master[lchip]->bridge_inner_mode)
        {
            SetDsNextHop4W(V, isLeaf_f,  p_ds,   1);
        }
    }
    if (g_usw_nh_master[lchip]->cid_use_4w && p_sys_dsnh->cid_valid && !p_sys_dsnh->is_nexthop8_w)
    {
        if (DRV_FROM_TMM(lchip))
        {
            stats_ptr = p_sys_dsnh->cid&0x3ff;
            is_4w_cid = 1;
        }
        else
        {
            stats_ptr = ((1 << 8) | (p_sys_dsnh->cid&0xff));
        }
        SetDsNextHop4W(V, statsPtrLow_f,           p_ds,   stats_ptr);
    }
    else
    {
        SetDsNextHop4W(V, statsPtrLow_f,        p_ds,   p_sys_dsnh->stats_ptr);
    }

    if (p_sys_dsnh->copy_dscp)
    {
        SetDsNextHop4W(V, dscpRemarkMode_f,        p_ds,   3);
    }
    else if (p_sys_dsnh->map_dscp)
    {
        SetDsNextHop4W(V, dscpRemarkMode_f,        p_ds,   2);
    }
    if(p_sys_dsnh->is_encap&&DRV_IS_TMG(lchip)) /*TMG: categoryValid indicate encap packet */
    {
        SetDsNextHop4W(V, categoryValid_f,            p_ds,   1);
    }

    switch(p_sys_dsnh->share_type)
    {
    case SYS_NH_SHARE_TYPE_L23EDIT:
        if ( !p_sys_dsnh->is_nexthop8_w)
        {
            SetDsNextHop4W(V, deriveStagCos_f,      p_ds,  0);
            SetDsNextHop4W(V, replaceStagCos_f,     p_ds,  0);
            SetDsNextHop4W(V, stagCfi_f,            p_ds,  0);
            SetDsNextHop4W(V, stagCos_f,            p_ds,  0);
            if (is_4w_cid)
            {
                SetDsNextHop4W(V, statsPtrHigh_f,        p_ds,   (p_sys_dsnh->cid >> 10));/*TMM...*/
            }
            else
            {
                SetDsNextHop4W(V, statsPtrHigh_f,        p_ds,   (p_sys_dsnh->stats_ptr >> stats_low_bits));
            }
            SetDsNextHop4W(V, cwIndex_f,             p_ds,   p_sys_dsnh->cw_index);
            SetDsNextHop4W(V, outerEditLocation_f,   p_ds,   p_sys_dsnh->outer_edit_location);
            SetDsNextHop4W(V, outerEditPtrType_f,    p_ds,   p_sys_dsnh->outer_edit_ptr_type);
            SetDsNextHop4W(V, innerEditPtrType_f,    p_ds,   p_sys_dsnh->inner_edit_ptr_type);
            SetDsNextHop4W(V, outerEditPtr_f,        p_ds,   p_sys_dsnh->outer_edit_ptr);
            SetDsNextHop4W(V, innerEditPtr_f,        p_ds,   p_sys_dsnh->inner_edit_ptr);

        }
        else if (p_sys_dsnh->vlan_xlate_mode == 1)
        {
            do_vlan_edit = 1;
        }
        break;

    case SYS_NH_SHARE_TYPE_VLANTAG:
        do_vlan_edit = 1;
        if ((!p_sys_dsnh->is_nexthop8_w) && (p_sys_dsnh->logic_port_check || p_sys_dsnh->logic_dest_port))
        {
            /*using 4w do logic port or logic port check*/
            ctag_mode = 1;
        }

        break;

    case SYS_NH_SHARE_TYPE_MAC_DA:

        SYS_USW_SET_HW_MAC(mac_da,  p_sys_dsnh->mac_da)
        SetDsNextHop4W(A, macDa_f,         p_ds,   mac_da);
         /*SetDsNextHop4W(V, u1_g3_macDaMcastMode_f,     p_ds,   0);*/
        SetDsNextHop4W(V, useTtlFromPacket_f,   p_ds,   p_sys_dsnh->use_packet_ttl);
        SetDsNextHop4W(V, ttlNoDecrease_f,         p_ds,   p_sys_dsnh->ttl_no_dec);
        break;

    case SYS_NH_SHARE_TYPE_L2EDIT_VLAN:
        if (is_4w_cid)
        {
            SetDsNextHop4W(V, u1_g4_statsPtrHigh_f,        p_ds,   (p_sys_dsnh->cid >> 10));/*TMM...*/
        }
        else
        {
            SetDsNextHop4W(V, u1_g4_statsPtrHigh_f,         p_ds,   (p_sys_dsnh->stats_ptr >> stats_low_bits));
        }

        if (p_sys_dsnh->outer_edit_valid)
        {
            SetDsNextHop4W(V, outerEditPtrValid_f,    p_ds,   p_sys_dsnh->outer_edit_valid);
            SetDsNextHop4W(V, u1_g4_outerEditLocation_f,    p_ds,   p_sys_dsnh->outer_edit_location);
            SetDsNextHop4W(V, u1_g4_outerEditPtrType_f,     p_ds,   p_sys_dsnh->outer_edit_ptr_type);
            SetDsNextHop4W(V, u1_g4_outerEditPtr_f,         p_ds,   p_sys_dsnh->outer_edit_ptr);
        }
        else
        {
            SetDsNextHop4W(V, u1_g4_outerEditLocation_f,    p_ds,   p_sys_dsnh->logic_port_check);
            SetDsNextHop4W(V, u1_g4_outerEditPtr_f,         p_ds,   p_sys_dsnh->logic_dest_port);
        }

        SetDsNextHop4W(V, u1_g4_svlanTagDisable_f,      p_ds,   p_sys_dsnh->svlan_tag_disable);
        SetDsNextHop4W(V, u1_g4_taggedMode_f,           p_ds,   p_sys_dsnh->tagged_mode);
        SetDsNextHop4W(V, u1_g4_outputSvlanIdValid_f,   p_ds,   p_sys_dsnh->output_svlan_id_valid);
        SetDsNextHop4W(V, u1_g4_outputSvlanId_f,        p_ds,   p_sys_dsnh->output_svlan_id);
        SetDsNextHop4W(V, u1_g4_replaceStagCos_f,       p_ds,   p_sys_dsnh->replace_stag_cos);
        SetDsNextHop4W(V, u1_g4_deriveStagCos_f,        p_ds,   p_sys_dsnh->derive_stag_cos);
        SetDsNextHop4W(V, u1_g4_stagCfi_f,              p_ds,   p_sys_dsnh->stag_cfi);
        SetDsNextHop4W(V, u1_g4_stagCos_f,              p_ds,   p_sys_dsnh->stag_cos);
        SetDsNextHop4W(V, u1_g4_svlanTpid_f,            p_ds,   p_sys_dsnh->svlan_tpid);
        SetDsNextHop4W(V, u1_g4_svlanTpidEn_f,          p_ds,   p_sys_dsnh->svlan_tpid_en);
        SetDsNextHop4W(V, useTtlFromPacket_f,           p_ds,   p_sys_dsnh->use_packet_ttl);
        SetDsNextHop4W(V, u1_g4_cosSwap_f,              p_ds,   p_sys_dsnh->cos_swap);
        break;

    default:
        break;
    }

    if (do_vlan_edit)
    {
        SetDsNextHop4W(V, stagActionUponOuterVlan_f,         p_ds,   p_sys_dsnh->stag_action);
        if (is_4w_cid)
        {
            SetDsNextHop4W(V, u1_g2_statsPtrHigh_f,        p_ds,   (p_sys_dsnh->cid >> 10));/*TMM...*/
        }
        else
        {
            SetDsNextHop4W(V, u1_g2_statsPtrHigh_f,         p_ds,   (p_sys_dsnh->stats_ptr >> stats_low_bits));
        }
        SetDsNextHop4W(V, svlanTagDisable_f,      p_ds,   p_sys_dsnh->svlan_tag_disable);
        SetDsNextHop4W(V, taggedMode_f,           p_ds,   p_sys_dsnh->tagged_mode);
        SetDsNextHop4W(V, outputSvlanIdValid_f,   p_ds,   p_sys_dsnh->output_svlan_id_valid);
        SetDsNextHop4W(V, outputSvlanId_f,        p_ds,   p_sys_dsnh->output_svlan_id);
        SetDsNextHop4W(V, u1_g2_replaceStagCos_f,       p_ds,   p_sys_dsnh->replace_stag_cos);
        SetDsNextHop4W(V, u1_g2_deriveStagCos_f,        p_ds,   p_sys_dsnh->derive_stag_cos);
        SetDsNextHop4W(V, u1_g2_stagCfi_f,              p_ds,   p_sys_dsnh->stag_cfi);
        SetDsNextHop4W(V, u1_g2_stagCos_f,              p_ds,   p_sys_dsnh->stag_cos);
        SetDsNextHop4W(V, svlanTpid_f,            p_ds,   p_sys_dsnh->svlan_tpid);
        SetDsNextHop4W(V, svlanTpidEn_f,          p_ds,   p_sys_dsnh->svlan_tpid_en);
        SetDsNextHop4W(V, cvlanTagDisable_f,      p_ds,   p_sys_dsnh->cvlan_tag_disable);
        SetDsNextHop4W(V, ctagShareMode_f,        p_ds,   ctag_mode?1:p_sys_dsnh->ctag_share_mode);
        SetDsNextHop4W(V, outputCvlanIdValid_f,   p_ds,   ctag_mode?p_sys_dsnh->logic_port_check:p_sys_dsnh->output_cvlan_id_valid);
        SetDsNextHop4W(V, logicDestPort15Bit_f,        p_ds,   ctag_mode?(p_sys_dsnh->logic_dest_port>>15):0);
        SetDsNextHop4W(V, outputCvlanId_f,        p_ds,   ctag_mode?(p_sys_dsnh->logic_dest_port & 0xFFF):p_sys_dsnh->output_cvlan_id);
        SetDsNextHop4W(V, replaceCtagCos_f,       p_ds,   ctag_mode?((p_sys_dsnh->logic_dest_port>>12)&0x1):p_sys_dsnh->replace_ctag_cos);
        SetDsNextHop4W(V, copyCtagCos_f,          p_ds,   ctag_mode?((p_sys_dsnh->logic_dest_port>>13)&0x1):p_sys_dsnh->copy_ctag_cos);
        SetDsNextHop4W(V, useTtlFromPacket_f,     p_ds,   p_sys_dsnh->use_packet_ttl);
        SetDsNextHop4W(V, tpidSwap_f,             p_ds,   p_sys_dsnh->tpid_swap | p_sys_dsnh->mirror_tag_add);
        SetDsNextHop4W(V, cosSwap_f,              p_ds,   p_sys_dsnh->cos_swap);
    }

    if (p_sys_dsnh->is_wlan_encap && (!p_sys_dsnh->is_vxlan_route_op))
    {
        SetDsNextHop4W(V, capwapWsiBitmap3_f,                p_ds,   0);
        SetDsNextHop4W(V, u1_g5_statsPtrHigh_f,                    p_ds,   (p_sys_dsnh->stats_ptr >> stats_low_bits));
    }
    else if (p_sys_dsnh->stats_ptr && p_sys_dsnh->is_nexthop8_w)
    {
        SetDsNextHop8W(V, u1_g2_statsPtrHigh_f,         p_ds,   (p_sys_dsnh->stats_ptr >> stats_low_bits));
    }
    /*----------mapping dsnexthop8w---------------*/
    if ( p_sys_dsnh->is_nexthop8_w)
    {
        SetDsNextHop8W(V, cvlanTagged_f,            p_ds,   p_sys_dsnh->cvlan_strip?0:1);

        SetDsNextHop8W(V, nextHopBypass_f,                p_ds,   p_sys_dsnh->next_hop_bypass);
        SetDsNextHop8W(V, stpIdValid_f,                   p_ds,   p_sys_dsnh->stp_id_valid);
        SetDsNextHop8W(V, stpId_f,                  p_ds,   p_sys_dsnh->stp_id);
        SetDsNextHop8W(V, txTodTimestamp_f,               p_ds,   p_sys_dsnh->keep_igs_ts?0:1);
        SetDsNextHop8W(V, reCalculateSymmetricalHash_f,   p_ds,   p_sys_dsnh->xerpsan_en);

        SetDsNextHop8W(V, outerEditHashEn_f,             p_ds,   p_sys_dsnh->hash_num?1:0);
        SetDsNextHop8W(V, outerEditHashNum_f,            p_ds,   p_sys_dsnh->hash_num);
        SetDsNextHop8W(V, innerEditHashEn_f,             p_ds,   p_sys_dsnh->hash_num?1:0);
        SetDsNextHop8W(V, innerEditHashNum_f,            p_ds,   p_sys_dsnh->hash_num);

        SetDsNextHop8W(V, logicPortCheck_f,               p_ds,   p_sys_dsnh->logic_port_check);
        SetDsNextHop8W(V, logicDestPort_f,                p_ds,   p_sys_dsnh->logic_dest_port);
        SetDsNextHop8W(V, outerEditLocation_f,            p_ds,   p_sys_dsnh->outer_edit_location);
        SetDsNextHop8W(V, outerEditPtrType_f,             p_ds,   p_sys_dsnh->outer_edit_ptr_type);
        SetDsNextHop8W(V, outerEditPtr_f,                 p_ds,   p_sys_dsnh->outer_edit_ptr);
        SetDsNextHop8W(V, innerEditPtrType_f,             p_ds,   p_sys_dsnh->inner_edit_ptr_type);
        SetDsNextHop8W(V, innerEditPtr_f,                 p_ds,   p_sys_dsnh->inner_edit_ptr);
        SetDsNextHop8W(V, isVxlanRouteOp_f,               p_ds,   p_sys_dsnh->is_vxlan_route_op);

        SetDsNextHop8W(V, fidValid_f,                     p_ds,   p_sys_dsnh->fid_valid);

        if (p_sys_dsnh->flow_flag_valid)
        {
            SetDsNextHop8W(V, aclQosUseOuterInfoValid_f,          p_ds,   1);
            SetDsNextHop8W(V, aclKeyMergeInnerAndOuterHdrValid_f, p_ds,   1);
            SetDsNextHop8W(V, ipfixUseOuterInfoValid_f,           p_ds,   1);
            SetDsNextHop8W(V, aclQosUseOuterInfo_f,               p_ds,   p_sys_dsnh->acl_use_outer);
            SetDsNextHop8W(V, aclKeyMergeInnerAndOuterHdr_f,      p_ds,   p_sys_dsnh->acl_merge);
            SetDsNextHop8W(V, ipfixUseOuterInfo_f,                p_ds,   p_sys_dsnh->ipfix_use_outer);
        }

        if (p_sys_dsnh->fid_valid)
        {
            SetDsNextHop8W(V, fid_f,                p_ds,   p_sys_dsnh->fid);
            SetDsNextHop8W(V, fidValid_f,           p_ds,  1);
            SetDsNextHop8W(V, u2Type_f,             p_ds,  0);
        }
        else if (p_sys_dsnh->span_en)
        {
            SetDsNextHop8W(V, globalSpanId_f,      p_ds,   p_sys_dsnh->fid);
            SetDsNextHop8W(V, u2Type_f,             p_ds,  3);

        }
        else if (p_sys_dsnh->cw_index)
        {
            SetDsNextHop8W(V, u2_g1_cwIndex_f,            p_ds,   p_sys_dsnh->cw_index);
            SetDsNextHop8W(V, u2Type_f,             p_ds,  3);

        }
        else if(p_sys_dsnh->cid_valid)
        {
            SetDsNextHop8W(V, u2Type_f,             p_ds,  2);
            if(!DRV_IS_TMG(lchip))
            {
                SetDsNextHop8W(V, categoryValid_f,            p_ds,   1);
            }
            if (DRV_FROM_TMM(lchip))
            {
                SetDsNextHop8W(V, nhpCategoryId_f,            p_ds,   p_sys_dsnh->cid);
            }
            else
            {
                SetDsNextHop8W(V, capwapWsiBitmapEn_f,           p_ds,   ((p_sys_dsnh->cid&0x80)? 1 : 0));
                SetDsNextHop8W(V, capwapWsiBitmap0_f,            p_ds,   (p_sys_dsnh->cid&0x7f));
            }
        }
        else if (p_sys_dsnh->esi_id_index_en)
        {
            SetDsNextHop8W(V, u2Type_f,             p_ds,  2);
            SetDsNextHop8W(V, categoryValid_f,            p_ds,   1);
            SetDsNextHop8W(V, capwapWsiBitmapEn_f,           p_ds,   ((p_sys_dsnh->cid&0x80)?1:0));
            SetDsNextHop8W(V, capwapWsiBitmap0_f,            p_ds,   (p_sys_dsnh->cid&0x7f));
        }

        if ((p_sys_dsnh->is_wlan_encap) && (!p_sys_dsnh->is_vxlan_route_op))
        {
            SetDsNextHop8W(V, isCapwapEncap_f,            p_ds,   1);
            SetDsNextHop8W(V, rid_f,                p_ds,   p_sys_dsnh->rid);
            SetDsNextHop8W(V, capwapMcTunnelEn_f,   p_ds,   p_sys_dsnh->wlan_mc_en);
            SetDsNextHop8W(V, destIsDot11_f,        p_ds,   p_sys_dsnh->is_dot11);
            SetDsNextHop8W(V, destCapwapTunnelType_f, p_ds, p_sys_dsnh->wlan_tunnel_type);
            SYS_USW_SET_HW_MAC(mac_da,  p_sys_dsnh->mac_da)
            SetDsNextHop8W(V, radioMacHigh_f, p_ds, (mac_da[1]&0xF800)>>11);

            SetDsNextHop4W(A, radioMacLow_f, p_ds, mac_da);

            SetDsNextHop8W(V, capwapWsiBitmapEn_f,               p_ds,   0);
            SetDsNextHop8W(V, capwapWsiBitmap0_f,                p_ds,   0);
            SetDsNextHop8W(V, capwapWsiBitmap1_f,                p_ds,   0);
            SetDsNextHop8W(V, capwapWsiBitmap2_f,                p_ds,   0);
        }
        else if (p_sys_dsnh->is_wlan_encap && p_sys_dsnh->is_vxlan_route_op)
        {
            /*udf edit profile*/
             /*-SYS_USW_SET_HW_MAC(mac_da,  p_sys_dsnh->mac_da)*/
            SetDsNextHop8W(V, isCapwapEncap_f,            p_ds,   1);
            SetDsNextHop8W(V, radioMacHigh_f, p_ds, (*((uint16*)&p_sys_dsnh->mac_da[4])&0xF800)>>11);
            SetDsNextHop4W(A, radioMacLow_f, p_ds, p_sys_dsnh->mac_da);
            SetDsNextHop8W(V, capwapMcTunnelEn_f,        p_ds,   ((p_sys_dsnh->rid&1)?1:0));
            SetDsNextHop8W(V, destCapwapTunnelType_f,    p_ds,   ((p_sys_dsnh->rid>>1)&0x3));
            SetDsNextHop8W(V, destIsDot11_f,             p_ds,   ((p_sys_dsnh->rid>>3)&0x1));
            SetDsNextHop8W(V, capwapWsiBitmap0_f,        p_ds,       (((p_sys_dsnh->rid>>4)&0x7)<<4));
            SetDsNextHop8W(V, capwapWsiBitmap1_f,        p_ds,   \
                (((p_sys_dsnh->wlan_mc_en&0xf)<<1)|((p_sys_dsnh->rid>>7)&0x1)));
            SetDsNextHop8W(V, capwapWsiBitmap2_f,        p_ds,       ((p_sys_dsnh->wlan_mc_en>>4)&0x3));
            SetDsNextHop4W(V, capwapWsiBitmap3_f,        p_ds,       ((p_sys_dsnh->wlan_mc_en>>6)&0x3));
        }
        else
        {
            SetDsNextHop4W(V, svlanTagDisable_f,         p_ds,   p_sys_dsnh->svlan_tag_disable);
            SetDsNextHop4W(V, svlanTpid_f,              p_ds,   p_sys_dsnh->svlan_tpid);
            SetDsNextHop4W(V, svlanTpidEn_f,            p_ds,   p_sys_dsnh->svlan_tpid_en);
        }
        if (DRV_FROM_TMM(lchip) && p_sys_dsnh->is_nexthop8_w)/*innerEditPtr is over 4w and 8w*/
        {
            SetDsNextHop8W(V, innerEditPtr_f,                 p_ds,   p_sys_dsnh->inner_edit_ptr);
        }
        if ( (p_sys_dsnh->offset >> SYS_NH_DSNH_INTERNAL_SHIFT) == SYS_NH_DSNH_INTERNAL_BASE)
        {
            *p_offset = *p_offset / 2;
        }
        return CTC_E_NONE;
    }

    if ( (p_sys_dsnh->offset >> SYS_NH_DSNH_INTERNAL_SHIFT) == SYS_NH_DSNH_INTERNAL_BASE)
    {
        DsNextHop8W_m dsnh8w;
        sal_memset(&dsnh8w, 0, sizeof(dsnh8w));
        offset = (p_sys_dsnh->offset & ((1 << SYS_NH_DSNH_INTERNAL_SHIFT) - 1));

        CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_NEXTHOP_INTERNAL,
                                                          offset / 2, &dsnh8w));

        if (offset % 2 == 0)
        {
            sal_memcpy((uint8*)&dsnh8w, p_ds, DRV_TABLE_ENTRY_SIZE(lchip, DsNextHop4W_t));
        }
        else
        {
            sal_memcpy((uint8*)&dsnh8w + DRV_TABLE_ENTRY_SIZE(lchip, DsNextHop4W_t), p_ds, DRV_TABLE_ENTRY_SIZE(lchip, DsNextHop4W_t));
        }

        sal_memcpy(p_ds , &dsnh8w, DRV_TABLE_ENTRY_SIZE(lchip, DsNextHop8W_t));

        *p_offset = *p_offset / 2;

        return CTC_E_NONE;
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_dsnexthop(uint8 lchip, sys_nexthop_t* p_sys_dsnh, void *p_ds)
{
    hw_mac_addr_t mac = {0};
    uint32 stats_ptr = 0;
    uint8 stats_low_bits = 0;
    stats_low_bits = DRV_IS_DUET2(lchip)?9:10;

    p_sys_dsnh->share_type = GetDsNextHop4W(V, shareType_f, p_ds);
    p_sys_dsnh->is_nexthop8_w = GetDsNextHop4W(V, isNexthop8W_f, p_ds);
    p_sys_dsnh->dest_vlan_ptr = GetDsNextHop4W(V, destVlanPtr_f, p_ds);
    p_sys_dsnh->mtu_check_en = GetDsNextHop4W(V, mtuCheckEn_f, p_ds);
    p_sys_dsnh->aps_bridge_en = GetDsNextHop4W(V, apsBridgeEn_f, p_ds);
    p_sys_dsnh->payload_operation = GetDsNextHop4W(V, payloadOperation_f, p_ds);
    p_sys_dsnh->is_leaf = GetDsNextHop4W(V, isLeaf_f, p_ds);
    p_sys_dsnh->svlan_tagged = GetDsNextHop4W(V, svlanTagged_f, p_ds);
    p_sys_dsnh->vlan_xlate_mode = GetDsNextHop4W(V, vlanXlateMode_f, p_ds);
    p_sys_dsnh->strip_l2_hdr =  GetDsNextHop4W(V, stripL2Hdr_f,  p_ds);
    if (DRV_FROM_AT(lchip))
    {
        p_sys_dsnh->strip_l2_hdr = GetDsNextHop4W(V, stripHdrMode_f, p_ds);/*AT*/
    }
    p_sys_dsnh->destVlanPtrDeriveMode = GetDsNextHop4W(V, destVlanPtrDeriveMode_f, p_ds);
    p_sys_dsnh->use_packet_ttl = GetDsNextHop4W(V, useTtlFromPacket_f, p_ds);
    p_sys_dsnh->dvp_tbl_valid = GetDsNextHop4W(V, skipPopDvpTbl_f, p_ds)?0:1;
    p_sys_dsnh->srv6_aps_en = GetDsNextHop4W(V, xAluEn_f, p_ds);
    stats_ptr = GetDsNextHop4W(V, statsPtrLow_f, p_ds);
    if(p_sys_dsnh->is_nexthop8_w)
    {
        if (GetDsNextHop8W(V, aclQosUseOuterInfoValid_f, p_ds)
            || GetDsNextHop8W(V, aclKeyMergeInnerAndOuterHdrValid_f, p_ds)
        || GetDsNextHop8W(V, ipfixUseOuterInfoValid_f, p_ds))
        {
            p_sys_dsnh->flow_flag_valid = 1;
            p_sys_dsnh->acl_use_outer = GetDsNextHop8W(V, aclQosUseOuterInfo_f, p_ds);
            p_sys_dsnh->acl_merge = GetDsNextHop8W(V, aclKeyMergeInnerAndOuterHdr_f, p_ds);
            p_sys_dsnh->ipfix_use_outer = GetDsNextHop8W(V, ipfixUseOuterInfo_f, p_ds);
        }
        p_sys_dsnh->logic_dest_port = GetDsNextHop8W(V, logicDestPort_f, p_ds);
        p_sys_dsnh->logic_port_check = GetDsNextHop8W(V, logicPortCheck_f, p_ds);
        p_sys_dsnh->stats_ptr = (GetDsNextHop8W(V, u1_g2_statsPtrHigh_f, p_ds)<<stats_low_bits) + stats_ptr;

        if (((!DRV_FROM_TMG(lchip))&&(GetDsNextHop8W(V, categoryValid_f, p_ds))) || ((2 == GetDsNextHop8W(V, u2Type_f, p_ds))&&(DRV_FROM_AT(lchip))) || ((3 == GetDsNextHop8W(V, u2Type_f, p_ds))&&(DRV_IS_TMG(lchip))))
        {
            p_sys_dsnh->cid_valid = 1;
            if (DRV_FROM_TMM(lchip))
            {
                p_sys_dsnh->cid = GetDsNextHop8W(V, nhpCategoryId_f, p_ds);
            }
            else
            {
                p_sys_dsnh->cid = (GetDsNextHop8W(V, capwapWsiBitmapEn_f, p_ds) << 6) + GetDsNextHop8W(V, capwapWsiBitmap0_f, p_ds);
            }
        }
    }
    else
    {
        if (SYS_NH_OP_ROUTE_COMPACT == p_sys_dsnh->payload_operation)
        {
            p_sys_dsnh->share_type = SYS_NH_SHARE_TYPE_MAC_DA;
        }
        switch (p_sys_dsnh->share_type)
        {
            case SYS_NH_SHARE_TYPE_L23EDIT:
                stats_ptr = (GetDsNextHop4W(V, statsPtrHigh_f, p_ds) << stats_low_bits) + stats_ptr;
                break;
            case SYS_NH_SHARE_TYPE_VLANTAG:
                if(GetDsNextHop4W(V, ctagShareMode_f, p_ds))
                {
                    p_sys_dsnh->logic_port_check = GetDsNextHop4W(V, outputCvlanIdValid_f, p_ds);
                    p_sys_dsnh->logic_dest_port = (GetDsNextHop4W(V, logicDestPort15Bit_f, p_ds) << 15)
                                                + (GetDsNextHop4W(V, copyCtagCos_f, p_ds) << 13)
                                                + (GetDsNextHop4W(V, replaceCtagCos_f, p_ds) << 12)
                                                + (GetDsNextHop4W(V, outputCvlanId_f, p_ds));
                }
                break;
            case SYS_NH_SHARE_TYPE_MAC_DA:
                GetDsNextHop4W(A, macDa_f, p_ds,  mac);
                SYS_USW_SET_USER_MAC(p_sys_dsnh->mac_da, mac);
                p_sys_dsnh->use_packet_ttl = GetDsNextHop4W(V, useTtlFromPacket_f,   p_ds);
                p_sys_dsnh->ttl_no_dec = GetDsNextHop4W(V, ttlNoDecrease_f, p_ds);
                break;
            case SYS_NH_SHARE_TYPE_L2EDIT_VLAN:
                stats_ptr = (GetDsNextHop4W(V, u1_g4_statsPtrHigh_f, p_ds) << stats_low_bits) + stats_ptr;
                if(GetDsNextHop4W(V, outerEditPtrValid_f, p_ds))
                {
                    p_sys_dsnh->logic_dest_port = GetDsNextHop4W(V, u1_g4_outerEditPtr_f, p_ds);
                    p_sys_dsnh->logic_port_check = GetDsNextHop4W(V, u1_g4_outerEditLocation_f, p_ds);
                }

                break;
            default:
                break;
        }

        if (g_usw_nh_master[lchip]->cid_use_4w && stats_ptr && (0 == p_sys_dsnh->cid_valid))
        {
            p_sys_dsnh->cid_valid = 1;
            p_sys_dsnh->cid = (!DRV_FROM_TMM(lchip))? (stats_ptr&0xFF) : stats_ptr;
        }
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_update_dsnexthop(uint8 lchip, sys_nexthop_t* p_sys_dsnh)
{
    DsNextHop8W_m dsnh8w;
    uint32 dsnh_offset = 0;

    dsnh_offset = p_sys_dsnh->offset;
    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_NEXTHOP_8W, dsnh_offset, &dsnh8w));

    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_HASH_NUM))
    {
        if ( p_sys_dsnh->hash_num >= 1)
        {
            SetDsNextHop8W(V, outerEditHashEn_f,      &dsnh8w,   1);
            SetDsNextHop8W(V, outerEditHashNum_f,   &dsnh8w,    p_sys_dsnh->hash_num-1);
            SetDsNextHop8W(V, innerEditHashEn_f,       &dsnh8w,   1);
            SetDsNextHop8W(V, innerEditHashNum_f,    &dsnh8w,    p_sys_dsnh->hash_num-1);
        }
        else
        {
            SetDsNextHop8W(V, outerEditHashEn_f,      &dsnh8w,   0);
            SetDsNextHop8W(V, outerEditHashNum_f,   &dsnh8w,   0);
            SetDsNextHop8W(V, innerEditHashEn_f,       &dsnh8w,   0);
            SetDsNextHop8W(V, innerEditHashNum_f,    &dsnh8w,   0);
        }
    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_LDP))
    {
        SetDsNextHop8W(V, logicDestPort_f,       &dsnh8w,   p_sys_dsnh->logic_dest_port);
    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_STRIP_L2))
    {
        SetDsNextHop8W(V, stripHdrMode_f,        &dsnh8w,   p_sys_dsnh->strip_l2_hdr);
    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_MTU_CHECK))
    {
        SetDsNextHop8W(V, mtuCheckEn_f,       &dsnh8w,   p_sys_dsnh->mtu_check_en);
    }

    CTC_ERROR_RETURN(sys_usw_nh_set_asic_table(lchip, SYS_NH_ENTRY_TYPE_NEXTHOP_8W, dsnh_offset,  &dsnh8w));

    return CTC_E_NONE;
}

int32
sys_usw_nh_update_dsnexthop_4w(uint8 lchip, sys_nexthop_t* p_sys_dsnh)
{
    DsNextHop4W_m dsnh4w;
    uint32 dsnh_offset = 0;
    hw_mac_addr_t mac_da;

    dsnh_offset = p_sys_dsnh->offset;
    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_NEXTHOP_4W, dsnh_offset, &dsnh4w));

    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_MAC_VLAN))
    {
        if (GetDsNextHop4W(V, payloadOperation_f, &dsnh4w) == SYS_NH_OP_ROUTE_COMPACT)
        {
            SYS_USW_SET_HW_MAC(mac_da,  p_sys_dsnh->mac_da)
            SetDsNextHop4W(A, macDa_f,       &dsnh4w,   mac_da);
        }
        SetDsNextHop4W(V, destVlanPtr_f,  &dsnh4w,  p_sys_dsnh->dest_vlan_ptr);

    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_LDP)) /*only SYS_NH_SHARE_TYPE_L2EDIT_VLAN support logic port, for overlay bind logicPort*/
    {
        SetDsNextHop4W(V, u1_g4_outerEditPtr_f,  &dsnh4w,   p_sys_dsnh->logic_dest_port);
    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_STRIP_L2))
    {
        SetDsNextHop4W(V, stripHdrMode_f,  &dsnh4w,   p_sys_dsnh->strip_l2_hdr);
    }
    if (CTC_FLAG_ISSET(p_sys_dsnh->update_type, SYS_NH_UPDATE_TYPE_MTU_CHECK))
    {
        SetDsNextHop8W(V, mtuCheckEn_f,       &dsnh4w,   p_sys_dsnh->mtu_check_en);
    }

    CTC_ERROR_RETURN(sys_usw_nh_set_asic_table(lchip, SYS_NH_ENTRY_TYPE_NEXTHOP_4W, dsnh_offset,  &dsnh4w));

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_dsl2edit_eth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;
    uint32 macda_en = 0;
    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->mac_da)

    if ((mac[0] == 0) && (mac[1] == 0))
    {
        macda_en = 0;
    }
    else
    {
        if (p_sys_l2edit->is_dot11 && p_sys_l2edit->derive_mcast_mac_for_trill && p_sys_l2edit->derive_mcast_mac_for_mpls)
        {
            /*wds: mac da means dest bssid, new mac da retrive from original packet, only used for splic l2 */
            macda_en = 0;
        }
        else
        {
            macda_en = 1;
        }
    }

    SetDsL2EditEth3W(V, discardType_f,           p_ds,  0);
    SetDsL2EditEth3W(V, discard_f,               p_ds,  0);
    SetDsL2EditEth3W(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
    SetDsL2EditEth3W(V, l2RewriteType_f,         p_ds,  p_sys_l2edit->l2_rewrite_type);
    SetDsL2EditEth3W(V, dot11SubType_f,          p_ds,  p_sys_l2edit->dot11_sub_type);
    SetDsL2EditEth3W(V, mapCos_f,                p_ds,  p_sys_l2edit->map_cos);
    SetDsL2EditEth3W(V, portMacSaEn_f,           p_ds,  0);
    SetDsL2EditEth3W(V, deriveMacFromLabel_f,    p_ds,  p_sys_l2edit->derive_mac_from_label);
    SetDsL2EditEth3W(V, macDaEn_f,               p_ds,  0);
    SetDsL2EditEth3W(V, overwriteEtherType_f,    p_ds,  0);
    SetDsL2EditEth3W(V, layer2EditType_f,        p_ds, p_sys_l2edit->is_dot11?2:0);
    SetDsL2EditEth3W(V, packetType_f,            p_ds,  0);
    if ((p_sys_l2edit->output_cvid || p_sys_l2edit->output_cvid_valid)
       && (0 == p_sys_l2edit->is_8w) && (0 == p_sys_l2edit->output_vid) && (0 == p_sys_l2edit->output_vid_valid))
    {
        SetDsL2EditEth3W(V, outputVlanIdValid_f,     p_ds,  1);
        SetDsL2EditEth3W(V, outputVlanId_f,  p_ds,  p_sys_l2edit->output_cvid);
        SetDsL2EditEth3W(V, outputVlanIdIsSvlan_f,   p_ds,  0);
        SetDsL2EditEth3W(V, overwriteIntfCvlanId_f,     p_ds,  1);
    }
    else if(p_sys_l2edit->output_vid || p_sys_l2edit->output_vid_valid)
    {
        SetDsL2EditEth3W(V, outputVlanIdIsSvlan_f,   p_ds,  1);
        SetDsL2EditEth3W(V, outputVlanIdValid_f,     p_ds,  1);
        SetDsL2EditEth3W(V, overwriteIntfSvlanId_f,          p_ds,  1);
        SetDsL2EditEth3W(V, outputVlanId_f,          p_ds,  p_sys_l2edit->output_vid);
    }
    else
    {
        SetDsL2EditEth3W(V, outputVlanId_f,          p_ds,  0xFFF);
    }
    SetDsL2EditEth3W(V, macDaEn_f,                p_ds,  macda_en);
    SetDsL2EditEth3W(A, macDa_f,                p_ds,  mac);
    SetDsL2EditEth3W(V, deriveFcoeMacSa_f,       p_ds,  0);
    SetDsL2EditEth3W(V, deriveMcastMacForTrill_f,p_ds,  p_sys_l2edit->derive_mcast_mac_for_trill);
    SetDsL2EditEth3W(V, deriveMcastMacForMpls_f, p_ds,  p_sys_l2edit->derive_mcast_mac_for_mpls);
    SetDsL2EditEth3W(V, deriveMcastMacForIp_f,   p_ds,  p_sys_l2edit->derive_mcast_mac_for_ip);
    SetDsL2EditEth3W(V, deriveFcoeMac_f,         p_ds,  p_sys_l2edit->fpma);
    SetDsL2EditEth3W(V, systemRouterMac_f,       p_ds,  0);

    if (p_sys_l2edit->is_8w)
    {
        SetDsL2EditEth6W(V, cosPhbPtr_f,                    p_ds,  p_sys_l2edit->cos_domain);
        SetDsL2EditEth6W(V, fcoeOverTrillMacSaEn_f,         p_ds,  0);
        SetDsL2EditEth6W(V, spanExtendHeaderCopyHash_f,     p_ds,  0);
        SetDsL2EditEth6W(V, spanExtendHeaderValid_f ,       p_ds,  0);

        if(p_sys_l2edit->use_port_mac)
        {
            SetDsL2EditEth3W(V, outputVlanId_f,          p_ds,  0);
            SetDsL2EditEth6W(V, ecmpTunnelMacDaEn_f ,           p_ds,  1);
        }

        if(p_sys_l2edit->update_mac_sa)
        {
            SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->mac_sa);
            SetDsL2EditEth6W(A, macSa_f,     p_ds,  mac);
            SetDsL2EditEth6W(V, macSaEn_f,  p_ds,  1);
        }

        if (p_sys_l2edit->ether_type)
        {
            SetDsL2EditEth6W(V, etherTypeRewriteValid_f,  p_ds,  1);
            SetDsL2EditEth6W(V, etherType_f,  p_ds,  p_sys_l2edit->ether_type);
        }

        if (p_sys_l2edit->output_cvid || p_sys_l2edit->output_cvid_valid)
        {
            SetDsL2EditEth6W(V, outputCvlanIdValid_f,     p_ds,  1);
            SetDsL2EditEth6W(V, outputCvlanId_f,  p_ds,  p_sys_l2edit->output_cvid);
            SetDsL2EditEth6W(V, overwriteIntfCvlanId_f,  p_ds,  1);
        }

        SetDsL2EditEth6W(V, spanExtendHeaderValid_f,  p_ds,  p_sys_l2edit->is_span_ext_hdr);
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_dsl2edit_eth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds)
{
    hw_mac_addr_t mac = {0};
    if (GetDsL2EditEth3W(V, macDaEn_f,  p_ds))
    {
        GetDsL2EditEth3W(A, macDa_f, p_ds,  mac);
        SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_da, mac);
    }
    if (GetDsL2EditEth3W(V, outputVlanIdValid_f, p_ds))
    {
        p_sys_l2edit->output_vid = GetDsL2EditEth3W(V, outputVlanId_f, p_ds);
    }
    p_sys_l2edit->l2_rewrite_type = GetDsL2EditEth3W(V, l2RewriteType_f, p_ds);
    if (SYS_NH_L2EDIT_TYPE_ETH_8W == p_sys_l2edit->l2_rewrite_type)
    {
        p_sys_l2edit->is_8w = 1;
        if (GetDsL2EditEth6W(V, macSaEn_f,  p_ds))
        {
            p_sys_l2edit->update_mac_sa = 1;
            GetDsL2EditEth6W(A, macSa_f, p_ds,  mac);
            SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_sa, mac);
        }

        if (GetDsL2EditEth6W(V, outputCvlanIdValid_f,  p_ds))
        {
            p_sys_l2edit->output_cvid = GetDsL2EditEth6W(V, outputCvlanId_f, p_ds);
        }

        if (GetDsL2EditEth6W(V, etherTypeRewriteValid_f,  p_ds))
        {
            p_sys_l2edit->ether_type = GetDsL2EditEth6W(V, etherType_f, p_ds);
        }
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_dsl2edit_inner_swap(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac_da;
    SYS_USW_SET_HW_MAC(mac_da,  p_sys_l2edit->mac_da)

    if (DRV_FROM_TMM(lchip))
    {
        SetDsL2EditRwEth1X(V, discardType_f,           p_ds,  0);
        SetDsL2EditRwEth1X(V, discard_f,               p_ds,  0);
        SetDsL2EditRwEth1X(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
        SetDsL2EditRwEth1X(V, l2EditType_f,            p_ds,  p_sys_l2edit->l2_rewrite_type);
        SetDsL2EditRwEth1X(A, macDa_f,                 p_ds,  mac_da);
        SetDsL2EditRwEth1X(V, macDaRewriteEn_f,        p_ds,  1);
        SetDsL2EditRwEth1X(V, macDaValid_f,            p_ds,  1);
        SetDsL2EditRwEth1X(V, macSaRewriteEn_f,        p_ds,  p_sys_l2edit->update_mac_sa);
        SetDsL2EditRwEth1X(V, deriveMcastMacForIp_f,   p_ds,  p_sys_l2edit->derive_mcast_mac_for_ip);
        SetDsL2EditRwEth1X(V, deriveMcastMacForMpls_f, p_ds,  p_sys_l2edit->derive_mcast_mac_for_mpls);
    }
    else
    {
        SetDsL2EditInnerSwap(V, discardType_f,           p_ds,  0);
        SetDsL2EditInnerSwap(V, discard_f,               p_ds,  0);
        SetDsL2EditInnerSwap(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
        SetDsL2EditInnerSwap(V, l2RewriteType_f,         p_ds,  p_sys_l2edit->l2_rewrite_type);
        SetDsL2EditInnerSwap(A, macDa_f,                 p_ds,  mac_da);
        SetDsL2EditInnerSwap(V, replaceInnerMacDa_f,     p_ds,  1);
        SetDsL2EditInnerSwap(V, vlanId_f,                p_ds,  0);
        SetDsL2EditInnerSwap(V, vTagModifyMode_f,        p_ds,  0);
        if (p_sys_l2edit->strip_inner_vlan)
        {
            SetDsL2EditInnerSwap(V, vTagOp_f,                p_ds,  3);/*del stag*/
        }
    }
    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_dsl2edit_inner_swap(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds)
{
    hw_mac_addr_t mac = {0};
    if (DRV_FROM_TMM(lchip))
    {
        if (GetDsL2EditRwEth1X(V, macDaValid_f, p_ds))
        {
            GetDsL2EditRwEth1X(A, macDa_f, p_ds, mac);
        }
    }
    else
    {
        if (GetDsL2EditInnerSwap(V, replaceInnerMacDa_f, p_ds))
        {
            GetDsL2EditInnerSwap(A, macDa_f, p_ds, mac);
        }
    }
    SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_da, mac);
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_dsl2edit_swap(uint8 lchip, sys_dsl2edit_of6w_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;

    SetDsL2EditSwap(V, discardType_f,           p_ds,  0);
    SetDsL2EditSwap(V, discard_f,               p_ds,  0);
    SetDsL2EditSwap(V, extraHeaderType_f,       p_ds,  0);

    SetDsL2EditSwap(V, dsType_f,            p_ds, SYS_NH_DS_TYPE_L2EDIT );
    SetDsL2EditSwap(V, l2RewriteType_f ,    p_ds, SYS_NH_L2EDIT_TYPE_MAC_SWAP );
    SetDsL2EditSwap(V, deriveMcastMac_f,    p_ds,  1);
    SetDsL2EditSwap(V, outputVlanIdValid_f, p_ds,  1);

    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->p_flex_edit->mac_da);
    SetDsL2EditSwap(A, macDa_f,                 p_ds,  mac);
    SYS_USW_SET_HW_MAC(mac, p_sys_l2edit->p_flex_edit->mac_sa);
    SetDsL2EditSwap(A, macSa_f,                 p_ds,  mac);

    SetDsL2EditSwap(V, _type_f,              p_ds, (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACDA)?1:0));
    SetDsL2EditSwap(V, overwriteEtherType_f, p_ds, (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACSA)?1:0));

    return CTC_E_NONE;

}


int32
sys_usw_nh_map_dsl2edit_of6w(uint8 lchip, sys_dsl2edit_of6w_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;

    SetDsL2EditOf(V, cCfi_f,             p_ds,  0);
    SetDsL2EditOf(V, sCfi_f,             p_ds,  0);
    SetDsL2EditOf(V, cosPhbPtr_f,        p_ds,  0);

    SetDsL2EditOf(V, discardType_f,           p_ds,  0);
    SetDsL2EditOf(V, discard_f,               p_ds,  0);
    SetDsL2EditOf(V, dsType_f,                p_ds,  SYS_NH_DS_TYPE_L2EDIT);
    SetDsL2EditOf(V, l2RewriteType_f,         p_ds, SYS_NH_L2EDIT_TYPE_OF);

    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->p_flex_edit->mac_da);
    SetDsL2EditOf(A, macDa_f,                 p_ds,  mac);
    SYS_USW_SET_HW_MAC(mac, p_sys_l2edit->p_flex_edit->mac_sa);
    SetDsL2EditOf(A, macSa_f,                 p_ds,  mac);

    SetDsL2EditOf(V, etherType_f,     p_ds, p_sys_l2edit->p_flex_edit->ether_type);

    if (p_sys_l2edit->vlan_profile_id)
    {
        SetDsL2EditOf(V, sVlanId_f,                p_ds, p_sys_l2edit->p_flex_edit->new_svid);
        SetDsL2EditOf(V, sCos_f,        p_ds,  p_sys_l2edit->p_flex_edit->new_scos);
        SetDsL2EditOf(V, cVlanId_f,                p_ds, p_sys_l2edit->p_flex_edit->new_cvid);
        SetDsL2EditOf(V, cCos_f,        p_ds,  p_sys_l2edit->p_flex_edit->new_ccos);
        SetDsL2EditOf(V, vlanActionProfileId_f,        p_ds,  p_sys_l2edit->vlan_profile_id);
    }

    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ETHERTYPE))
    {
        SetDsL2EditOf(V, replaceEtherType_f,     p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACDA))
    {
        SetDsL2EditOf(V, replaceMacDa_f,     p_ds, 1 );
        SetDsL2EditOf(V, ofMacDaValid_f,     p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACSA))
    {
        SetDsL2EditOf(V, replaceMacSa_f,     p_ds, 1 );
        SetDsL2EditOf(V, ofMacSaValid_f,     p_ds, 1 );
    }
    SetDsL2EditOf(V, portDot1QValid_f,     p_ds, CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_FOLLOW_PORT_DOT1Q_TYPE));
    return CTC_E_NONE;

}

int32
sys_usw_nh_map_dsl3edit_of6w(uint8 lchip, ctc_misc_nh_flex_edit_param_t* p_flex_edit, void *p_ds, uint32* p_offset)
{
    uint8 flex_tos = 0;

    SetDsL3EditOf6W(V, discard_f ,          p_ds, 0);
    SetDsL3EditOf6W(V, discardType_f ,      p_ds, 0);
    SetDsL3EditOf6W(V, nextEditPtrValid_f , p_ds, 0);
    SetDsL3EditOf6W(V, outerEditPtr_f ,     p_ds, 0);
    SetDsL3EditOf6W(V, outerEditPtrType_f , p_ds, 0);
    SetDsL3EditOf6W(V, statsPtr_f ,         p_ds, 0);

    SetDsL3EditOf6W(V, dsType_f,            p_ds, SYS_NH_DS_TYPE_L3EDIT);
    SetDsL3EditOf6W(V, l3RewriteType_f,     p_ds, SYS_NH_L3EDIT_TYPE_OF8W);

    SetDsL3EditOf6W(V, ipDa_f,     p_ds, p_flex_edit->ip_da.ipv4);
    SetDsL3EditOf6W(V, ipSa_f,     p_ds, p_flex_edit->ip_sa.ipv4);
    SetDsL3EditOf6W(V, protocol_f, p_ds, p_flex_edit->protocol);
    SetDsL3EditOf6W(V, ttl_f ,     p_ds, p_flex_edit->ttl);

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
    {
        SetDsL3EditOf6W(V, replaceIpDa_f , p_ds, 1 );
        SetDsL3EditOf6W(V, replaceIpSa_f , p_ds, 1 );
        SetDsL3EditOf6W(V, copyIpDa_f , p_ds, 1 );
        SetDsL3EditOf6W(V, copyIpSa_f , p_ds, 1 );
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA))
    {
        SetDsL3EditOf6W(V, replaceIpSa_f , p_ds, 1 );
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
        {
            /*swap + replace, using ipsa from nexthop do replace*/
            SetDsL3EditOf6W(V, copyIpDa_f , p_ds, 0);
        }
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA))
    {
        SetDsL3EditOf6W(V, replaceIpDa_f , p_ds, 1 );
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
        {
            /*swap + replace, using ipda from nexthop do replace*/
            SetDsL3EditOf6W(V, copyIpSa_f , p_ds, 0);
        }
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TTL))
    {
        SetDsL3EditOf6W(V, replaceTtl_f, p_ds, 1 );
    }
    else if(CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_DECREASE_TTL))
    {
        SetDsL3EditOf6W(V, decreaseTtl_f, p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ECN))
    {
        if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_ASSIGN)
        {
            SetDsL3EditOf6W(V, ecnRemarkMode_f,     p_ds, 1 );
            flex_tos |= (p_flex_edit->ecn & 0x3);
        }
        else if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_MAP)
        {
            SetDsL3EditOf6W(V, ecnRemarkMode_f,     p_ds, 2 );
        }
    }

    /*1:use assign; 1: map; 3:copy*/
    if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_ASSIGN )
    {
        SetDsL3EditOf6W(V, dscpRemarkMode_f, p_ds, 1 );
        flex_tos |= ((p_flex_edit->dscp_or_tos & 0x3F) << 2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_MAP )
    {
        SetDsL3EditOf6W(V, dscpRemarkMode_f, p_ds,  2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_PACKET )
    {
        SetDsL3EditOf6W(V, dscpRemarkMode_f, p_ds,  3);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_NONE )
    {
        SetDsL3EditOf6W(V, dscpRemarkMode_f, p_ds,  0);
    }

    SetDsL3EditOf6W(V, tos_f, p_ds, flex_tos);
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_PROTOCOL))
    {
        SetDsL3EditOf6W(V, replaceProtocol_f, p_ds, 1 );
    }

    if (p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_ICMP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_CODE))
        {
            SetDsL3EditOf6W(V, replaceIcmpv4Code_f, p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_TYPE))
        {
            SetDsL3EditOf6W(V, replaceIcmpv4Type_f, p_ds, 1 );
        }
        SetDsL3EditOf6W(V, l4SourcePort_f , p_ds, p_flex_edit->icmp_type);
        SetDsL3EditOf6W(V, l4DestPort_f , p_ds, p_flex_edit->icmp_code);

    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_GRE)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_GRE_KEY))
        {
            SetDsL3EditOf6W(V, replaceGreKey_f, p_ds, 1 );
        }

        SetDsL3EditOf6W(V, l4SourcePort_f , p_ds, (p_flex_edit->gre_key >> 16));
        SetDsL3EditOf6W(V, l4DestPort_f , p_ds, (p_flex_edit->gre_key & 0xFFFF) );
    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_UDPORTCP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
        {
            SetDsL3EditOf6W(V, replaceL4SourcePort_f , p_ds, 1 );
            SetDsL3EditOf6W(V, replaceL4DestPort_f, p_ds, 1 );
            SetDsL3EditOf6W(V, copyL4SourcePort_f , p_ds, 1 );
            SetDsL3EditOf6W(V, copyL4DestPort_f, p_ds, 1 );
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_DST_PORT))
        {
            SetDsL3EditOf6W(V, replaceL4DestPort_f, p_ds, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
            {
                SetDsL3EditOf6W(V, copyL4SourcePort_f , p_ds, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_SRC_PORT))
        {
            SetDsL3EditOf6W(V, replaceL4SourcePort_f , p_ds, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
            {
                SetDsL3EditOf6W(V, copyL4DestPort_f , p_ds, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TCP_PORT))
        {
            SetDsL3EditOf6W(V, replaceTcpPort_f, p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_UDP_PORT))
        {
            SetDsL3EditOf6W(V, replaceUdpPort_f, p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_UPDATE_UDP_CHKSUM))
        {
            SetDsL3EditOf6W(V, replaceTs_f, p_ds, 1 );
        }
        SetDsL3EditOf6W(V, l4SourcePort_f , p_ds, p_flex_edit->l4_src_port);
        SetDsL3EditOf6W(V, l4DestPort_f , p_ds, p_flex_edit->l4_dst_port);
    }

    return CTC_E_NONE;

}
int32
sys_usw_nh_map_dsl3edit_of12w(uint8 lchip, ctc_misc_nh_flex_edit_param_t* p_flex_edit, void *p_ds, uint32* p_offset)
{
    DsL3EditOf12W_m dsl3edit;
    uint8 is_have_l4 = 0;
    uint8 flex_tos = 0;
    ipv6_addr_t ipv6;
    hw_mac_addr_t mac;
    DsL3EditOf12WIpv6L4_m ipv6_l4;

    sal_memset(&dsl3edit, 0, sizeof(dsl3edit));
    sal_memset(&ipv6, 0, sizeof(ipv6_addr_t));
    sal_memset(&ipv6_l4, 0, sizeof(ipv6_l4));

    SetDsL3EditOf12W(V, discard_f,            &dsl3edit, 0);
    SetDsL3EditOf12W(V, discardType_f,        &dsl3edit, 0);
    SetDsL3EditOf12W(V, nextEditPtrValid_f,   &dsl3edit, 0);
    SetDsL3EditOf12W(V, outerEditPtr_f,       &dsl3edit, 0);
    SetDsL3EditOf12W(V, outerEditPtrType_f,   &dsl3edit, 0);
    SetDsL3EditOf12W(V, statsPtr_f,           &dsl3edit, 0);


    SetDsL3EditOf12W(V, dsType_f,       &dsl3edit, SYS_NH_DS_TYPE_L3EDIT);
    SetDsL3EditOf12W(V, l3RewriteType_f, &dsl3edit, SYS_NH_L3EDIT_TYPE_OF16W);

    if (p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_ARP)
    {
        DsL3EditOf12WArpData_m arp_data;
        sal_memset(&arp_data, 0, sizeof(arp_data));

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_HT))
        {
            SetDsL3EditOf12WArpData(V, hardwareType_f, &arp_data, p_flex_edit->arp_ht);
            SetDsL3EditOf12WArpData(V, replaceHt_f, &arp_data, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_HLEN))
        {
            SetDsL3EditOf12WArpData(V, hardwareAddLen_f, &arp_data, p_flex_edit->arp_halen);
            SetDsL3EditOf12WArpData(V, replaceHa_f, &arp_data, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_OP))
        {
            SetDsL3EditOf12WArpData(V, opCode_f ,  &arp_data, p_flex_edit->arp_op);
            SetDsL3EditOf12WArpData(V, replaceOpCode_f, &arp_data, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_PT))
        {
            SetDsL3EditOf12WArpData(V, protocolType_f, &arp_data, p_flex_edit->arp_pt);
            SetDsL3EditOf12WArpData(V, replacePt_f, &arp_data, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_PLEN))
        {
            SetDsL3EditOf12WArpData(V, protocolAddLen_f, &arp_data, p_flex_edit->arp_palen );
            SetDsL3EditOf12WArpData(V, replacePa_f, &arp_data, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_SHA))
        {
            SYS_USW_SET_HW_MAC(mac, p_flex_edit->arp_sha);
            SetDsL3EditOf12WArpData(A, senderHardwareAdd_f, &arp_data, mac);
            SetDsL3EditOf12WArpData(V, replaceSha_f, &arp_data, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_SPA))
        {
            SetDsL3EditOf12WArpData(V, senderProtocolAdd_f, &arp_data, p_flex_edit->arp_spa);
            SetDsL3EditOf12WArpData(V, replaceSpa_f, &arp_data, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_THA))
        {
            SYS_USW_SET_HW_MAC(mac, p_flex_edit->arp_tha);
            SetDsL3EditOf12WArpData(A, targetHardwareAdd_f, &arp_data, mac);
            SetDsL3EditOf12WArpData(V, replaceTha_f , &arp_data, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ARP_TPA))
        {
            SetDsL3EditOf12WArpData(V, targetProtocolAdd_f, &arp_data, p_flex_edit->arp_tpa);
            SetDsL3EditOf12WArpData(V, replaceTpa_f, &arp_data, 1 );
        }

        SetDsL3EditOf12W(A, data_f, &dsl3edit,  &arp_data);
        SetDsL3EditOf12W(V, editType_f,               &dsl3edit,  2);
        sal_memcpy(p_ds , &dsl3edit, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditOf12W_t));
        return CTC_E_NONE;
    }
    else if (p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_ICMP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_CODE))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceIcmpv6Code_f,     &ipv6_l4, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_TYPE))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceIcmpv6Type_f,     &ipv6_l4, 1 );
        }
        SetDsL3EditOf12WIpv6L4(V, l4SourcePort_f ,  &ipv6_l4, p_flex_edit->icmp_type);
        SetDsL3EditOf12WIpv6L4(V, l4DestPort_f , &ipv6_l4, p_flex_edit->icmp_code);
        is_have_l4 = 1;

    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_GRE)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_GRE_KEY))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceGreKey_f, &ipv6_l4, 1 );
        }

        SetDsL3EditOf12WIpv6L4(V, l4SourcePort_f, &ipv6_l4, (p_flex_edit->gre_key >> 16) );
        SetDsL3EditOf12WIpv6L4(V, l4DestPort_f, &ipv6_l4, (p_flex_edit->gre_key & 0xFFFF) );
        is_have_l4 = 1;
    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_UDPORTCP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceL4SourcePort_f , &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, replaceL4DestPort_f, &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, copyL4SourcePort_f , &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, copyL4DestPort_f, &ipv6_l4, 1 );
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_DST_PORT))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceL4DestPort_f, &ipv6_l4, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
            {
                SetDsL3EditOf12WIpv6L4(V, copyL4SourcePort_f , &ipv6_l4, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_SRC_PORT))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceL4SourcePort_f , &ipv6_l4, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
            {
                SetDsL3EditOf12WIpv6L4(V, copyL4DestPort_f , &ipv6_l4, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TCP_PORT))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceTcpPort_f, &ipv6_l4, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_UDP_PORT))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceUdpPort_f, &ipv6_l4, 1 );
        }
        SetDsL3EditOf12WIpv6L4(V, l4SourcePort_f , &ipv6_l4, p_flex_edit->l4_src_port);
        SetDsL3EditOf12WIpv6L4(V, l4DestPort_f , &ipv6_l4, p_flex_edit->l4_dst_port);
        is_have_l4 = 1;
    }
    else if(CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_PROTOCOL))
    {
        is_have_l4 = 1;
    }

    if ((CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA) &&
        CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA)))
    {
        if (is_have_l4)
        {
            SYS_NH_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " Feature not supported \n");
			return CTC_E_NOT_SUPPORT;

        }
    }


    if (is_have_l4)
    {
        SetDsL3EditOf12WIpv6L4(V, copyIpDa_f ,       &ipv6_l4, 0);
        SetDsL3EditOf12WIpv6L4(V, copyIpSa_f ,       &ipv6_l4, 0);

        CTC_MAX_VALUE_CHECK(p_flex_edit->flow_label, 0xFFFFF);
        SetDsL3EditOf12WIpv6L4(V, flowLabel_f , &ipv6_l4, p_flex_edit->flow_label&0xFFFFF);
        SetDsL3EditOf12WIpv6L4(V, protocol_f ,  &ipv6_l4, p_flex_edit->protocol);
        SetDsL3EditOf12WIpv6L4(V, ttl_f ,       &ipv6_l4, p_flex_edit->ttl);

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceIpDa_f ,     &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, replaceIpSa_f ,     &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, copyIpDa_f ,     &ipv6_l4, 1 );
            SetDsL3EditOf12WIpv6L4(V, copyIpSa_f ,     &ipv6_l4, 1 );
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceIpDa_f , &ipv6_l4, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
            {
                SetDsL3EditOf12WIpv6L4(V, copyIpSa_f ,     &ipv6_l4, 0 );
            }
            ipv6[0] = p_flex_edit->ip_da.ipv6[3];
            ipv6[1] = p_flex_edit->ip_da.ipv6[2];
            ipv6[2] = p_flex_edit->ip_da.ipv6[1];
            ipv6[3] = p_flex_edit->ip_da.ipv6[0];
            SetDsL3EditOf12WIpv6L4(A, ip_f,         &ipv6_l4,  ipv6);
        }
        else  if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceIpSa_f ,     &ipv6_l4, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
            {
                SetDsL3EditOf12WIpv6L4(V, copyIpDa_f ,     &ipv6_l4, 0 );
            }
            ipv6[0] = p_flex_edit->ip_sa.ipv6[3];
            ipv6[1] = p_flex_edit->ip_sa.ipv6[2];
            ipv6[2] = p_flex_edit->ip_sa.ipv6[1];
            ipv6[3] = p_flex_edit->ip_sa.ipv6[0];
            SetDsL3EditOf12WIpv6L4(A, ip_f,         &ipv6_l4,  ipv6);
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TTL))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceTtl_f,     &ipv6_l4, 1 );
        }
        else if(CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_DECREASE_TTL))
        {
            SetDsL3EditOf12WIpv6L4(V, decreaseTtl_f,     &ipv6_l4, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ECN))
        {
            if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_ASSIGN)
            {
                SetDsL3EditOf12WIpv6L4(V, ecnRemarkMode_f,     &ipv6_l4, 1 );
                flex_tos |= (p_flex_edit->ecn & 0x3);
            }
            else if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_MAP)
            {
                SetDsL3EditOf12WIpv6L4(V, ecnRemarkMode_f,     &ipv6_l4, 2 );
            }
        }

        if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_ASSIGN )
        {
            SetDsL3EditOf12WIpv6L4(V, dscpRemarkMode_f ,     &ipv6_l4, 1 );
            flex_tos |= ((p_flex_edit->dscp_or_tos & 0x3F) << 2);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_MAP )
        {
            SetDsL3EditOf12WIpv6L4(V, dscpRemarkMode_f,     &ipv6_l4,  2);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_PACKET )
        {
            SetDsL3EditOf12WIpv6L4(V, dscpRemarkMode_f,     &ipv6_l4,  3);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_NONE )
        {
            SetDsL3EditOf12WIpv6L4(V, dscpRemarkMode_f,     &ipv6_l4,  0);
        }


        SetDsL3EditOf12WIpv6L4(V, tos_f,     &ipv6_l4, flex_tos);
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_PROTOCOL))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceProtocol_f,     &ipv6_l4, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_FLOW_LABEL))
        {
            SetDsL3EditOf12WIpv6L4(V, replaceFlowLabel_f,     &ipv6_l4, 1 );
        }

        SetDsL3EditOf12W(A, u1_gIpv6L4_data_f, &dsl3edit,  &ipv6_l4);
        SetDsL3EditOf12W(V, editType_f,               &dsl3edit,  1);
        if ((p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_UDPORTCP) && CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_UPDATE_UDP_CHKSUM))
        {
            SetDsL3EditOf12W(V, replaceTs_f, &dsl3edit, 1 );
        }
    }
    else
    {
        DsL3EditOf12WIpv6Only_m ipv6_only;
        sal_memset(&ipv6_only, 0, sizeof(ipv6_only));

        ipv6[0] = p_flex_edit->ip_da.ipv6[3];
        ipv6[1] = p_flex_edit->ip_da.ipv6[2];
        ipv6[2] = p_flex_edit->ip_da.ipv6[1];
        ipv6[3] = p_flex_edit->ip_da.ipv6[0];
        SetDsL3EditOf12WIpv6Only(A, ipDa_f,     &ipv6_only,  ipv6);
        ipv6[0] = p_flex_edit->ip_sa.ipv6[3];
        ipv6[1] = p_flex_edit->ip_sa.ipv6[2];
        ipv6[2] = p_flex_edit->ip_sa.ipv6[1];
        ipv6[3] = p_flex_edit->ip_sa.ipv6[0];
        SetDsL3EditOf12WIpv6Only(A, ipSa_f,     &ipv6_only,  ipv6);
        CTC_MAX_VALUE_CHECK(p_flex_edit->flow_label, 0xFFFFF);
        SetDsL3EditOf12WIpv6Only(V, flowLabel_f ,     &ipv6_only, p_flex_edit->flow_label&0xFFFFF);
        SetDsL3EditOf12WIpv6Only(V, ttl_f ,        &ipv6_only, p_flex_edit->ttl);

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
        {
            SetDsL3EditOf12WIpv6Only(V, replaceIpDa_f ,     &ipv6_only, 1 );
            SetDsL3EditOf12WIpv6Only(V, replaceIpSa_f ,     &ipv6_only, 1 );
            SetDsL3EditOf12WIpv6Only(V, copyIpDa_f ,     &ipv6_only, 1 );
            SetDsL3EditOf12WIpv6Only(V, copyIpSa_f ,     &ipv6_only, 1 );
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA))
        {
            SetDsL3EditOf12WIpv6Only(V, replaceIpDa_f ,     &ipv6_only, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
            {
                SetDsL3EditOf12WIpv6Only(V, copyIpSa_f ,     &ipv6_only, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA))
        {
            SetDsL3EditOf12WIpv6Only(V, replaceIpSa_f ,     &ipv6_only, 1 );
            if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
            {
                SetDsL3EditOf12WIpv6Only(V, copyIpDa_f ,     &ipv6_only, 0 );
            }
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TTL))
        {
            SetDsL3EditOf12WIpv6Only(V, replaceTtl_f,     &ipv6_only, 1 );
        }
        else if(CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_DECREASE_TTL))
        {
            SetDsL3EditOf12WIpv6Only(V, decreaseTtl_f,     &ipv6_only, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ECN))
        {
            SetDsL3EditOf12WIpv6Only(V, ecnRemarkMode_f,     &ipv6_only, 1 );
            flex_tos |= (p_flex_edit->ecn & 0x3);
        }

        if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_ASSIGN )
        {
            SetDsL3EditOf12WIpv6Only(V, dscpRemarkMode_f ,     &ipv6_only, 1 );
            flex_tos |= ((p_flex_edit->dscp_or_tos & 0x3F) << 2);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_MAP )
        {
            SetDsL3EditOf12WIpv6Only(V, dscpRemarkMode_f,     &ipv6_only,  2);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_PACKET )
        {
            SetDsL3EditOf12WIpv6Only(V, dscpRemarkMode_f,     &ipv6_only,  3);
        }
        else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_NONE )
        {
            SetDsL3EditOf12WIpv6Only(V, dscpRemarkMode_f,     &ipv6_only,  0);
        }

        SetDsL3EditOf12WIpv6Only(V, tos_f,     &ipv6_only, flex_tos);
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_FLOW_LABEL))
        {
            SetDsL3EditOf12WIpv6Only(V, replaceFlowLabel_f,     &ipv6_only, 1 );
        }

        SetDsL3EditOf12W(A, u1_gIpv6Only_data_f, &dsl3edit,  &ipv6_only);
        SetDsL3EditOf12W(V, editType_f,               &dsl3edit,  0);
    }
    sal_memcpy(p_ds , &dsl3edit, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditOf12W_t));

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_dsmet(uint8 lchip, sys_met_t* p_sys_met, void *p_ds, uint32* p_offset)
{
    DsMetEntry3W_m dsmet3w;
    DsMetEntry6W_m dsmet6w;
    uint32 pbm[3] = {0};

    sal_memset(&dsmet3w, 0, sizeof(dsmet3w));
    sal_memset(&dsmet6w, 0, sizeof(dsmet6w));

    SetDsMetEntry3W(V, mcastMode_f,                  &dsmet3w,      p_sys_met->mcast_mode);
    SetDsMetEntry3W(V, nextHopExt_f,                 &dsmet3w,      p_sys_met->next_hop_ext);
    SetDsMetEntry3W(V, currentMetEntryType_f,        &dsmet3w,      p_sys_met->is_6w);
    SetDsMetEntry3W(V, nextMetEntryPtr_f,            &dsmet3w,      p_sys_met->next_met_entry_ptr);
    SetDsMetEntry3W(V, endLocalRep_f,                &dsmet3w,      p_sys_met->end_local_rep);
    SetDsMetEntry3W(V, phyPortCheckDiscard_f,        &dsmet3w,      p_sys_met->phy_port_chk_discard);
    SetDsMetEntry3W(V,isLinkAggregation_f,    &dsmet3w,      p_sys_met->is_agg);

    if (!p_sys_met->mcast_mode)
    {
        SetDsMetEntry3W(V, remoteChip_f,           &dsmet3w,      p_sys_met->remote_chip);
        if (p_sys_met->fid && DRV_FROM_TMM(lchip))
        {
            SetDsMetEntry3W(V, fidValid_f,        &dsmet3w,      1);
            SetDsMetEntry3W(V, logicDestPort_f,     &dsmet3w,      p_sys_met->fid);
        }
        else
        {
            SetDsMetEntry3W(V, logicDestPort_f,        &dsmet3w,      p_sys_met->logic_dest_port);
            SetDsMetEntry3W(V, logicPortCheckEn_f,     &dsmet3w,      p_sys_met->logic_port_check_en);
        }
        SetDsMetEntry3W(V, leafCheckEn_f,          &dsmet3w,      p_sys_met->leaf_check_en);
        SetDsMetEntry3W(V, logicPortTypeCheck_f,   &dsmet3w,      p_sys_met->logic_port_type_check);
        SetDsMetEntry3W(V, apsBridgeEn_f,          &dsmet3w,      p_sys_met->aps_bridge_en);
        SetDsMetEntry3W(V, cloudSecEn_f,           &dsmet3w,      p_sys_met->cloud_sec_en);
        SetDsMetEntry3W(V, ucastId_f,              &dsmet3w,      p_sys_met->dest_id);

        if (DRV_FROM_TMM(lchip) && p_sys_met->logic_repli_en)
        {
            SetDsMetEntry3W(V, replicationCtl_f,       &dsmet3w,     (2 << 18) | (p_sys_met->next_hop_ptr <<1));
        }
        else if (DRV_IS_DUET2(lchip) || DRV_IS_TSINGMA(lchip))
        {
            SetDsMetEntry3W(V, replicationCtl_f,       &dsmet3w,     ((p_sys_met->next_hop_ptr << 5) | p_sys_met->replicate_num));
        }
        else
        {
            SetDsMetEntry3W(V, replicationCtl_f,       &dsmet3w,     (1 << 18) | p_sys_met->next_hop_ptr);
        }
        SetDsMetEntry3W(V, forceBackEn_f,          &dsmet3w,      p_sys_met->force_back_en);
        SetDsMetEntry3W(V, useDestMapProfile_f,    &dsmet3w,      p_sys_met->is_destmap_profile);

        SetDsMetEntry3W(V, destIsTunnel_f,         &dsmet3w,      0);
        SetDsMetEntry3W(V, splitHorizonCheckEn_f,  &dsmet3w,      0);


    }
    else
    {
        pbm[0] = p_sys_met->port_bitmap[0];
        pbm[1] = p_sys_met->port_bitmap[1];
        SetDsMetEntry3W(A, portBitmap_f,           &dsmet3w,      pbm);
        SetDsMetEntry3W(V, portBitmapBase_f,       &dsmet3w,      p_sys_met->port_bitmap_base);
        /*used for vlan if bitmap, for lag replicate*/
        if (DRV_IS_TSINGMA(lchip))
        {
            SetDsMetEntry3W(V, portBitmapLagMode_f,         &dsmet3w,   1);
        }
        if (DRV_FROM_TMM(lchip)) /*TMM lagmode field in 3w*/
        {
            SetDsMetEntry3W(V, portBitmapLagL3Mode_f,         &dsmet3w,   p_sys_met->lag_l3_mode);/*TMM*/
        }
    }
    sal_memcpy(p_ds , &dsmet3w, DRV_TABLE_ENTRY_SIZE(lchip, DsMetEntry3W_t));

    /*----------mapping dsmet6w---------------*/
    if (p_sys_met->is_6w)
    {
        SetDsMetEntry6W(V, nextHopPtrType_f,             &dsmet6w,   p_sys_met->logic_repli_en);
        SetDsMetEntry6W(V, nextHopPtr_f,                 &dsmet6w,   p_sys_met->next_hop_ptr);
        //pbm[0] = p_sys_met->port_bitmap[2];
        //pbm[1] = p_sys_met->port_bitmap[3];
        //SetDsMetEntry6W(A, portBitmapHigh_f,         &dsmet6w,   pbm);

        SetDsMetEntry6W(V, portBitmapHighValid_f,         &dsmet6w,   0);
        if (DRV_IS_TSINGMA(lchip))
        {
            SetDsMetEntry6W(V, portBitmapLagMode_f,         &dsmet6w,   1);
            if (p_sys_met->fid)
            {
                pbm[0] = p_sys_met->fid;
                pbm[1] = 0;
                SetDsMetEntry6W(V, fidValid_f,         &dsmet6w,   1);
                SetDsMetEntry6W(A, portBitmapHigh_f,         &dsmet6w,   pbm);
            }
        }

        sal_memcpy(((uint8*)&dsmet6w), &dsmet3w, DRV_TABLE_ENTRY_SIZE(lchip, DsMetEntry3W_t));
        sal_memcpy(p_ds , &dsmet6w, DRV_TABLE_ENTRY_SIZE(lchip, DsMetEntry6W_t));

    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_dsmet(uint8 lchip, sys_met_t* p_sys_met, void *p_ds)
{

    if (GetDsMetEntry3W(V, mcastMode_f,  p_ds))/*bmp mode*/
    {
        GetDsMetEntry3W(A, portBitmap_f, p_ds, p_sys_met->port_bitmap);

    }


    return CTC_E_NONE;
}


int32
sys_usw_nh_map_dsmpls(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    SetDsL3EditMpls3W(V, discardType_f,         p_ds,   p_sys_mpls->discard_type);
    SetDsL3EditMpls3W(V, discard_f,             p_ds,   p_sys_mpls->discard);
    SetDsL3EditMpls3W(V, dsType_f,              p_ds,   p_sys_mpls->ds_type);
    SetDsL3EditMpls3W(V, l3RewriteType_f,       p_ds,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditMpls3W(V, nextEditPtrValid_f,    p_ds,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditMpls3W(V, outerEditPtrType_f,    p_ds,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditMpls3W(V, outerEditPtr_f,        p_ds,   p_sys_mpls->outer_editptr);
    SetDsL3EditMpls3W(V, logicDestPortHigh_f,   p_ds,   p_sys_mpls->logic_dest_port);
    SetDsL3EditMpls3W(V, deriveLabel_f,         p_ds,   p_sys_mpls->derive_label);
    SetDsL3EditMpls3W(V, mplsOamIndex_f,        p_ds,   p_sys_mpls->mpls_oam_index);
    SetDsL3EditMpls3W(V, labelType_f,           p_ds,   p_sys_mpls->label_type);
    SetDsL3EditMpls3W(V, srcDscpType_f,         p_ds,   p_sys_mpls->src_dscp_type);
    SetDsL3EditMpls3W(V, mcastLabel_f,          p_ds,   p_sys_mpls->mcast_label);
    SetDsL3EditMpls3W(V, mapTtlMode_f,          p_ds,   p_sys_mpls->map_ttl_mode);
    SetDsL3EditMpls3W(V, mapTtl_f,              p_ds,   p_sys_mpls->map_ttl);
    SetDsL3EditMpls3W(V, statsPtr_f,            p_ds,   p_sys_mpls->statsptr);
    SetDsL3EditMpls3W(V, entropyLabelEn_f,      p_ds,   p_sys_mpls->entropy_label_en);

    if (p_sys_mpls->derive_exp)
    {
        if (p_sys_mpls->exp == 1)
        {
            /*mapping*/
            SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  p_ds,  2);
            SetDsL3EditMpls3W(V, uMplsPhb_gPtr_mplsTcPhbPtr_f,  p_ds, p_sys_mpls->mpls_domain);
        }
        else if (p_sys_mpls->exp == 0)
        {
            /*copy*/
            SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  p_ds,  3);
        }
    }
    else
    {
        SetDsL3EditMpls3W(V, uMplsPhb_gRaw_labelTc_f,  p_ds,   p_sys_mpls->exp);
        SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  p_ds,  1);
    }
    SetDsL3EditMpls3W(V, ttlIndex_f,            p_ds,   p_sys_mpls->ttl_index);
    SetDsL3EditMpls3W(V, label_f,               p_ds,   p_sys_mpls->label);

    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_dsmpls(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds)
{

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_dsmpls_6w(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    ds0_t dsmpls;
    ds0_t dsmpls_6w;

    sal_memset(&dsmpls_6w, 0, sizeof(dsmpls_6w));

    p_sys_mpls->offset = *p_offset;
    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_L3EDIT_SPME,
                                                      p_sys_mpls->offset, &dsmpls_6w));


    sal_memset(&dsmpls, 0, sizeof(dsmpls));
    SetDsL3EditMpls3W(V, discardType_f,         &dsmpls,   p_sys_mpls->discard_type);
    SetDsL3EditMpls3W(V, discard_f,             &dsmpls,   p_sys_mpls->discard);
    SetDsL3EditMpls3W(V, dsType_f,              &dsmpls,   p_sys_mpls->ds_type);
    SetDsL3EditMpls3W(V, l3RewriteType_f,       &dsmpls,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditMpls3W(V, nextEditPtrValid_f,    &dsmpls,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditMpls3W(V, outerEditPtrType_f,    &dsmpls,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditMpls3W(V, outerEditPtr_f,        &dsmpls,   p_sys_mpls->outer_editptr);
    SetDsL3EditMpls3W(V, logicDestPortHigh_f,   &dsmpls,   p_sys_mpls->logic_dest_port);
    SetDsL3EditMpls3W(V, deriveLabel_f,         &dsmpls,   p_sys_mpls->derive_label);
    SetDsL3EditMpls3W(V, mplsOamIndex_f,        &dsmpls,   p_sys_mpls->mpls_oam_index);
    SetDsL3EditMpls3W(V, labelType_f,           &dsmpls,   p_sys_mpls->label_type);
    SetDsL3EditMpls3W(V, srcDscpType_f,         &dsmpls,   p_sys_mpls->src_dscp_type);
    SetDsL3EditMpls3W(V, mcastLabel_f,          &dsmpls,   p_sys_mpls->mcast_label);
    SetDsL3EditMpls3W(V, mapTtlMode_f,          &dsmpls,   p_sys_mpls->map_ttl_mode);
    SetDsL3EditMpls3W(V, mapTtl_f,              &dsmpls,   p_sys_mpls->map_ttl);
    SetDsL3EditMpls3W(V, statsPtr_f,            &dsmpls,   p_sys_mpls->statsptr);
    SetDsL3EditMpls3W(V, entropyLabelEn_f,      &dsmpls,   p_sys_mpls->entropy_label_en);

    if (p_sys_mpls->derive_exp)
    {
        /*Qos domain need retrieve, TBD*/
        if (p_sys_mpls->exp == 1)
        {
            /*mapping*/
            SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  &dsmpls,  2);
            SetDsL3EditMpls3W(V, uMplsPhb_gPtr_mplsTcPhbPtr_f,  &dsmpls, 0);
        }
        else if (p_sys_mpls->exp == 0)
        {
            /*copy*/
            SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  &dsmpls,  3);
        }
    }
    else
    {
        SetDsL3EditMpls3W(V, uMplsPhb_gRaw_labelTc_f,  &dsmpls,   p_sys_mpls->exp);
        SetDsL3EditMpls3W(V, mplsTcRemarkMode_f,  &dsmpls,  1);
    }
    SetDsL3EditMpls3W(V, ttlIndex_f,            &dsmpls,   p_sys_mpls->ttl_index);
    SetDsL3EditMpls3W(V, label_f,               &dsmpls,   p_sys_mpls->label);

    if (p_sys_mpls->offset % 2 == 0)
    {
        sal_memcpy((uint8*)&dsmpls_6w, &dsmpls, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditMpls3W_t));
    }
    else
    {
        sal_memcpy((uint8*)&dsmpls_6w + DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditMpls3W_t), &dsmpls, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditMpls3W_t));
    }

    sal_memcpy(p_ds , &dsmpls_6w, sizeof(dsmpls_6w));
    *p_offset = *p_offset / 2; /*dwfwd have two member*/
    return CTC_E_NONE;

}


int32
sys_usw_nh_map_dsmpls_12w(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    SetDsL3EditMpls12W(V, discardType_f,         p_ds,   p_sys_mpls->discard_type);
    SetDsL3EditMpls12W(V, discard_f,             p_ds,   p_sys_mpls->discard);
    SetDsL3EditMpls12W(V, dsType_f,              p_ds,   p_sys_mpls->ds_type);
    SetDsL3EditMpls12W(V, l3RewriteType_f,       p_ds,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditMpls12W(V, nextEditPtrValid_f,    p_ds,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditMpls12W(V, outerEditPtrType_f,    p_ds,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditMpls12W(V, outerEditPtr_f,        p_ds,   p_sys_mpls->outer_editptr);
    SetDsL3EditMpls12W(V, mplsLabel0_f,        p_ds,   p_sys_mpls->label_full[0]);
    SetDsL3EditMpls12W(V, mplsLabel1_f,        p_ds,   p_sys_mpls->label_full[1]);
    SetDsL3EditMpls12W(V, mplsLabel2_f,        p_ds,   p_sys_mpls->label_full[2]);
    SetDsL3EditMpls12W(V, mplsLabel3_f,        p_ds,   p_sys_mpls->label_full[3]);
    SetDsL3EditMpls12W(V, mplsLabel4_f,        p_ds,   p_sys_mpls->label_full[4]);
    SetDsL3EditMpls12W(V, mplsLabel5_f,        p_ds,   p_sys_mpls->label_full[5]);
    SetDsL3EditMpls12W(V, mplsLabel6_f,        p_ds,   p_sys_mpls->label_full[6]);
    SetDsL3EditMpls12W(V, mplsLabel7_f,        p_ds,   p_sys_mpls->label_full[7]);
    SetDsL3EditMpls12W(V, mplsLabel8_f,        p_ds,   p_sys_mpls->label_full[8]);
    SetDsL3EditMpls12W(V, mplsLabel9_f,        p_ds,   p_sys_mpls->label_full[9]);
    SetDsL3EditMpls12W(V, labelExpMode_f,        p_ds,   p_sys_mpls->derive_exp);
    SetDsL3EditMpls12W(V, pushLabelNumber_f,        p_ds,   p_sys_mpls->label_num);

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_dsl2edit_loopback(uint8 lchip, sys_dsl2edit_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    SetDsL2EditLoopback(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
    SetDsL2EditLoopback(V, l2RewriteType_f,         p_ds,  SYS_NH_L2EDIT_TYPE_LOOPBACK);
    SetDsL2EditLoopback(V, l2EditType_f,         p_ds,  DRV_ENUM(DRV_L2EDITTYPE_LOOPBACK));/*TMM...*/
    SetDsL2EditLoopback(V, lbDestMap_f,         p_ds,  p_sys_l2edit->dest_map);
    SetDsL2EditLoopback(V, lbNextHopPtr_f,         p_ds,  p_sys_l2edit->nexthop_ptr);
    SetDsL2EditLoopback(V, lbNextHopExt_f,         p_ds,  p_sys_l2edit->nexthop_ext);
    SetDsL2EditLoopback(V, lbBypassIpe_f,         p_ds,  p_sys_l2edit->bypass_ipe);/*TMM...*/
    SetDsL2EditLoopback(V, lbBypassIngressEdit_f,         p_ds,  p_sys_l2edit->bypass_igr_edit);/*AT...*/
    SetDsL2EditLoopback(V, lbSrcLocalPhyPortEn_f,         p_ds,  p_sys_l2edit->reback);
    SetDsL2EditLoopback(V, lbLogicPortInHeader_f,         p_ds,  p_sys_l2edit->lb_with_ldp);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_dsl3edit_loopback(uint8 lchip, sys_dsl2edit_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    SetDsL3EditLoopback(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
    SetDsL3EditLoopback(V, l2RewriteType_f,         p_ds,  SYS_NH_L3EDIT_TYPE_LOOPBACK);
    SetDsL3EditLoopback(V, lbDestMap_f,         p_ds,  p_sys_l2edit->dest_map);
    SetDsL3EditLoopback(V, lbNextHopPtr_f,         p_ds,  p_sys_l2edit->nexthop_ptr);
    SetDsL3EditLoopback(V, lbNextHopExt_f,         p_ds,  p_sys_l2edit->nexthop_ext);
    SetDsL3EditLoopback(V, l3EditType_f,         p_ds,  DRV_ENUM(DRV_L3EDITTYPE_LOOPBACK));/*TMM...*/
    SetDsL3EditLoopback(V, lbBypassIpe_f,         p_ds,  p_sys_l2edit->bypass_ipe);/*TMM...*/
    SetDsL3EditLoopback(V, lbBypassIngressEdit_f,         p_ds,  p_sys_l2edit->bypass_igr_edit);/*AT...*/
    SetDsL3EditLoopback(V, lbSrcLocalPhyPortEn_f,         p_ds,  p_sys_l2edit->reback);
    SetDsL3EditLoopback(V, lbLogicPortInHeader_f,         p_ds,  p_sys_l2edit->lb_with_ldp);
    return CTC_E_NONE;
}
int32
sys_usw_nh_map_dsl2edit_flex(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    DsL2EditFlex_m dsl2edit;
    uint32 gem_vlan[4] = {0};
    uint8  leave_num = 0;
    uint8  shift_left = 0;
    uint32 value =0;
    uint32 gem_port_pass = 0;

    sal_memset(&dsl2edit, 0, sizeof(dsl2edit));

    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_L2EDIT_FLEX_8W,
                                                      p_sys_l2edit->offset, &dsl2edit));

    GetDsL2EditFlex(A, rewriteString_f,        &dsl2edit, gem_vlan);
    /* output_vlan_id(gem_vlan) ether_type(logic_dest_port)*/
    leave_num = p_sys_l2edit->ether_type%8;
    shift_left = leave_num*16;
    value = gem_vlan[shift_left/32];
    value &= ~(0xFFFF<<(shift_left%32));
    gem_vlan[shift_left/32] = value | ((p_sys_l2edit->output_vid)<<(shift_left%32));
    SetDsL2EditFlex(V, dsType_f,               &dsl2edit,  SYS_NH_DS_TYPE_L2EDIT);
    SetDsL2EditFlex(V, l2RewriteType_f,        &dsl2edit,  SYS_NH_L2EDIT_TYPE_FLEX_8W);
    SetDsL2EditFlex(V, gemPortEditEn_f,        &dsl2edit,  1);
    SetDsL2EditFlex(A, rewriteString_f,        &dsl2edit,  gem_vlan);
    if (leave_num < 3)
    {
        gem_port_pass = GetDsL2EditFlex(V, packetType_f,       &dsl2edit);
        gem_port_pass |= (1<<leave_num);
        SetDsL2EditFlex(V, packetType_f,       &dsl2edit,  gem_port_pass);
    }
    else
    {
        gem_port_pass = GetDsL2EditFlex(V, rewriteByteNum_f,   &dsl2edit);
        gem_port_pass |= (1<<(leave_num-3));
        SetDsL2EditFlex(V, rewriteByteNum_f,   &dsl2edit,  gem_port_pass);
    }

    sal_memcpy(p_ds , &dsl2edit, DRV_TABLE_ENTRY_SIZE(lchip, DsL2EditFlex_t));

    return CTC_E_NONE;
}


int32
sys_usw_nh_map_tunnelv4(uint8 lchip, sys_dsl3edit_tunnelv4_t* p_sys_tunnel, void *p_ds, uint32* p_offset)
{
    SetDsL3EditTunnelV4(V, udpSrcPortCfgEn_f,        p_ds,   0);
    SetDsL3EditTunnelV4(V, autoIpProtocolTypeMode_f, p_ds,   p_sys_tunnel->ip_protocol_type?0:1);
    SetDsL3EditTunnelV4(V, keepAlive_f,              p_ds,   0);
    SetDsL3EditTunnelV4(V, udpSrcPortUseHash_f,            p_ds,   0);

    SetDsL3EditTunnelV4(V, ecnCopyMode_f,           p_ds,   p_sys_tunnel->ecn_mode);
    SetDsL3EditTunnelV4(V, discardType_f,           p_ds,   0);
    SetDsL3EditTunnelV4(V, discard_f,               p_ds,   0);
    SetDsL3EditTunnelV4(V, dsType_f,                p_ds,   p_sys_tunnel->ds_type);
    SetDsL3EditTunnelV4(V, l3RewriteType_f,         p_ds,   p_sys_tunnel->l3_rewrite_type);
    SetDsL3EditTunnelV4(V, nextEditPtrValid_f,      p_ds,   p_sys_tunnel->out_l2edit_valid);
    SetDsL3EditTunnelV4(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditTunnelV4(V, outerEditPtr_f,          p_ds,   p_sys_tunnel->out_l2edit_valid ? (p_sys_tunnel->l2edit_ptr) : 0);
    SetDsL3EditTunnelV4(V, ipSaValid_f,             p_ds,   p_sys_tunnel->ipsa_valid);
    SetDsL3EditTunnelV4(V, mtuSize_f,               p_ds,   p_sys_tunnel->mtu_size);
    SetDsL3EditTunnelV4(V, mapTtl_f,                p_ds,   p_sys_tunnel->map_ttl);
    SetDsL3EditTunnelV4(V, isatpTunnel_f,     p_ds,   p_sys_tunnel->isatp_tunnel);
    SetDsL3EditTunnelV4(V, copyDontFrag_f,          p_ds,   p_sys_tunnel->copy_dont_frag);
    SetDsL3EditTunnelV4(V, dontFrag_f,              p_ds,   p_sys_tunnel->dont_frag);
    SetDsL3EditTunnelV4(V, ttl_f,                   p_ds,   p_sys_tunnel->ttl);
    SetDsL3EditTunnelV4(V, tunnel6To4Sa_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa);
    SetDsL3EditTunnelV4(V, tunnel6To4Da_f,    p_ds,   p_sys_tunnel->tunnel6_to4_da);
    SetDsL3EditTunnelV4(V, mtuCheckEn_f,            p_ds,   p_sys_tunnel->mtu_check_en);
    SetDsL3EditTunnelV4(V, innerHeaderValid_f,      p_ds,   p_sys_tunnel->inner_header_valid);
    SetDsL3EditTunnelV4(V, innerHeaderType_f,       p_ds,   p_sys_tunnel->inner_header_type);
    SetDsL3EditTunnelV4(V, ipDa_f,                  p_ds,   p_sys_tunnel->ipda);
    SetDsL3EditTunnelV4(V, ipSaIndex_f,             p_ds,   p_sys_tunnel->ipsa_index);
    SetDsL3EditTunnelV4(V, statsPtr_f,              p_ds,   p_sys_tunnel->stats_ptr);
    SetDsL3EditTunnelV4(V, spanExtendHeaderValid_f,             p_ds,   p_sys_tunnel->xerspan_hdr_en);
    SetDsL3EditTunnelV4(V, spanExtendHeaderCopyHash_f,     p_ds,   p_sys_tunnel->xerspan_hdr_with_hash_en);
    SetDsL3EditTunnelV4(V, ipIdentificationType_f,           p_ds,   0);
    SetDsL3EditTunnelV4(V, packetLengthType_f,           p_ds,   1);
    if (p_sys_tunnel->out_l2edit_valid && (p_sys_tunnel->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditTunnelV4(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditTunnelV4(V, outerEditPtr_f,          p_ds,   (p_sys_tunnel->l2edit_ptr-MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }

    if (p_sys_tunnel->cloud_sec_en)
    {
        SetDsL3EditTunnelV4(V, dot1AeSaIndexLow_f,           p_ds,   (p_sys_tunnel->sc_index&0x7));
        SetDsL3EditTunnelV4(V, ipSaIndex_f,           p_ds,   ((p_sys_tunnel->sc_index>>3)&0xf));
        SetDsL3EditTunnelV4(V, dot1AeSciEn_f,           p_ds,   p_sys_tunnel->sci_en);
        SetDsL3EditTunnelV4(V, encryptVxlanTunnel_f,           p_ds,   1);
    }
    else
    {
        SetDsL3EditTunnelV4(V, encryptVxlanTunnel_f,           p_ds,   0);
    }

    if (p_sys_tunnel->udf_profile_id)
    {
        SetDsL3EditTunnelV4(V, flexTunnelEnable_f,           p_ds,   1);
        SetDsL3EditTunnelV4(V, flexHdrIndex_f,           p_ds,   ((p_sys_tunnel->udf_profile_id-1)&0x3));
        SetDsL3EditTunnelV4(V, dontFrag_f,           p_ds,   ((p_sys_tunnel->udf_profile_id-1)>>2)&0x1);
    }

    SetDsL3EditTunnelV4(V, dscpRemarkMode_f,        p_ds,   p_sys_tunnel->derive_dscp);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        /*assign*/
        SetDsL3EditTunnelV4(V, uDscpPhb_gRaw_dscp_f,    p_ds,   p_sys_tunnel->dscp);
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        /*map*/
        SetDsL3EditTunnelV4(V, uDscpPhb_gPtr_dscpPhbPtr_f,     p_ds,   p_sys_tunnel->dscp_domain);
    }

    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_GRE:
        SetDsL3EditTunnelV4(V, greKeyHigh_f,      p_ds,   (p_sys_tunnel->gre_key >> 16));
        SetDsL3EditTunnelV4(V, greKeyLow_f,       p_ds,   (p_sys_tunnel->gre_key & 0xFFFF));
        SetDsL3EditTunnelV4(V, greProtocol_f,     p_ds,   p_sys_tunnel->gre_protocol);
        SetDsL3EditTunnelV4(V, greFlags_f,        p_ds,   p_sys_tunnel->gre_flags);
        SetDsL3EditTunnelV4(V, greVersion_f,      p_ds,   p_sys_tunnel->gre_version);
        SetDsL3EditTunnelV4(V, greAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_gre_auto);
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6RD:
        SetDsL3EditTunnelV4(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        SetDsL3EditTunnelV4(V, tunnel6To4Ipv6PrefixLength_f,      p_ds,   p_sys_tunnel->tunnel6_to4_da_ipv6_prefixlen);
        SetDsL3EditTunnelV4(V, tunnel6To4Ipv4PrefixLength_f,      p_ds,   p_sys_tunnel->tunnel6_to4_da_ipv4_prefixlen);
        SetDsL3EditTunnelV4(V, tunnel6To4SaIpv6PrefixLength_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa_ipv6_prefixlen);
        SetDsL3EditTunnelV4(V, tunnel6To4SaIpv4PrefixLength_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa_ipv4_prefixlen);
        if (p_sys_tunnel->tunnel6_to4_sa)
        {
            SetDsL3EditTunnelV4(V, ipSa6To4High_f,    p_ds,   (p_sys_tunnel->ipsa_6to4 >> 16));
            SetDsL3EditTunnelV4(V, ipSa6To4Low_f,     p_ds,   (p_sys_tunnel->ipsa_6to4 & 0xFFFF));
        }
        else
        {
            SetDsL3EditTunnelV4(V, ipSaHigh_f,        p_ds,   (p_sys_tunnel->ipsa >> 16));
            SetDsL3EditTunnelV4(V, ipSaLow_f,         p_ds,   (p_sys_tunnel->ipsa & 0xFFFF));
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6TO4:
        SetDsL3EditTunnelV4(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        SetDsL3EditTunnelV4(V, ipSaHigh_f,        p_ds,   (p_sys_tunnel->ipsa >> 16));
        SetDsL3EditTunnelV4(V, ipSaLow_f,         p_ds,   (p_sys_tunnel->ipsa & 0xFFFF));
        if (p_sys_tunnel->l4_dest_port && p_sys_tunnel->l4_src_port)
        {
            SetDsL3EditTunnelV4(V, udpDestPort_f,     p_ds,   p_sys_tunnel->l4_dest_port);
            SetDsL3EditTunnelV4(V, udpSrcPort_f,      p_ds,   p_sys_tunnel->l4_src_port);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_NVGRE:
        SetDsL3EditTunnelV4(V, nvgreHeaderMode_f, p_ds,   1);
        SetDsL3EditTunnelV4(V, isNvgreEncaps_f,   p_ds,   1);
        SetDsL3EditTunnelV4(V, greAutoIdentifyProtocol_f,   p_ds,   1);
        SetDsL3EditTunnelV4(V, ipSa6To4High_f,    p_ds,   (p_sys_tunnel->ipsa >> 16));
        SetDsL3EditTunnelV4(V, ipSa6To4Low_f,     p_ds,   (p_sys_tunnel->ipsa & 0xFFFF));
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_VXLAN:
        SetDsL3EditTunnelV4(V, udpTunnelType_f,   p_ds,   1);
        SetDsL3EditTunnelV4(V, ipSa6To4High_f,    p_ds,   (p_sys_tunnel->ipsa >> 16));
        SetDsL3EditTunnelV4(V, ipSa6To4Low_f,     p_ds,   (p_sys_tunnel->ipsa & 0xFFFF));

        SetDsL3EditTunnelV4(V, isEvxlanTunnel_f,   p_ds,   p_sys_tunnel->is_evxlan);
        SetDsL3EditTunnelV4(V, protocolTypeSelIndex_f,   p_ds,   p_sys_tunnel->evxlan_protocl_index);

        SetDsL3EditTunnelV4(V, isGeneveTunnel_f,   p_ds,   p_sys_tunnel->is_geneve);
        SetDsL3EditTunnelV4(V, geneveAutoIdentifyProtocol_f,   p_ds,   p_sys_tunnel->is_geneve);

        SetDsL3EditTunnelV4(V, udpSrcPortCfgEn_f,   p_ds,   p_sys_tunnel->udp_src_port_en);
        SetDsL3EditTunnelV4(V, udpDestPort_f,   p_ds,   p_sys_tunnel->l4_src_port);
        SetDsL3EditTunnelV4(V, evxlanAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_vxlan_auto);
        if(p_sys_tunnel->vxlan_edit_idx)
        {
            SetDsL3EditTunnelV4(V, evxlanAutoIdentifyProtocol_f, p_ds,   (p_sys_tunnel->vxlan_edit_idx>>3)&0x01);
            SetDsL3EditTunnelV4(V, geneveAutoIdentifyProtocol_f, p_ds,   (p_sys_tunnel->vxlan_edit_idx>>2)&0x01);
            SetDsL3EditTunnelV4(V, protocolTypeSelIndex_f, p_ds,         (p_sys_tunnel->vxlan_edit_idx)&0x03);
        }
        break;
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_WLAN:
        SetDsL3EditTunnelV4(V, needCapwapEncrypt_f, p_ds, p_sys_tunnel->encrypt_en);
        SetDsL3EditTunnelV4(V, encryptKeyIndex_f, p_ds, p_sys_tunnel->encrypt_id);
        SetDsL3EditTunnelV4(V, radioMacEn_f, p_ds, p_sys_tunnel->rmac_en);
        SetDsL3EditTunnelV4(V, isUdpLite_f, p_ds, 0);
        SetDsL3EditTunnelV4(V, udpDestPort_f, p_ds, p_sys_tunnel->l4_dest_port);
        SetDsL3EditTunnelV4(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        SetDsL3EditTunnelV4(V, bssidBitmap_f, p_ds, p_sys_tunnel->bssid_bitmap);
        SetDsL3EditTunnelV4(V, keepAlive_f, p_ds, p_sys_tunnel->data_keepalive);
        break;
    default:
        break;
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_tunnelv4(uint8 lchip, sys_dsl3edit_tunnelv4_t* p_sys_tunnel, void *p_ds)
{
    p_sys_tunnel->ecn_mode = GetDsL3EditTunnelV4(V, ecnCopyMode_f, p_ds);
    p_sys_tunnel->ds_type = GetDsL3EditTunnelV4(V, dsType_f,   p_ds);
    p_sys_tunnel->l3_rewrite_type = GetDsL3EditTunnelV4(V, l3RewriteType_f, p_ds);
    p_sys_tunnel->out_l2edit_valid = GetDsL3EditTunnelV4(V, nextEditPtrValid_f, p_ds);
    p_sys_tunnel->l2edit_ptr = GetDsL3EditTunnelV4(V, outerEditPtr_f, p_ds);
    p_sys_tunnel->ipsa_valid = GetDsL3EditTunnelV4(V, ipSaValid_f, p_ds);
    p_sys_tunnel->mtu_size = GetDsL3EditTunnelV4(V, mtuSize_f,  p_ds);
    p_sys_tunnel->map_ttl = GetDsL3EditTunnelV4(V, mapTtl_f, p_ds);
    p_sys_tunnel->isatp_tunnel = GetDsL3EditTunnelV4(V, isatpTunnel_f, p_ds);
    p_sys_tunnel->copy_dont_frag = GetDsL3EditTunnelV4(V, copyDontFrag_f, p_ds);
    p_sys_tunnel->dont_frag = GetDsL3EditTunnelV4(V, dontFrag_f, p_ds);
    p_sys_tunnel->ttl = GetDsL3EditTunnelV4(V, ttl_f,      p_ds);
    p_sys_tunnel->tunnel6_to4_sa = GetDsL3EditTunnelV4(V, tunnel6To4Sa_f, p_ds);
    p_sys_tunnel->tunnel6_to4_da = GetDsL3EditTunnelV4(V, tunnel6To4Da_f, p_ds);
    p_sys_tunnel->mtu_check_en = GetDsL3EditTunnelV4(V, mtuCheckEn_f, p_ds);
    p_sys_tunnel->inner_header_valid = GetDsL3EditTunnelV4(V, innerHeaderValid_f, p_ds);
    p_sys_tunnel->inner_header_type = GetDsL3EditTunnelV4(V, innerHeaderType_f, p_ds);
    p_sys_tunnel->ipda = GetDsL3EditTunnelV4(V, ipDa_f,     p_ds);
    p_sys_tunnel->ipsa_index = GetDsL3EditTunnelV4(V, ipSaIndex_f, p_ds);
    p_sys_tunnel->stats_ptr = GetDsL3EditTunnelV4(V, statsPtr_f, p_ds);
    p_sys_tunnel->xerspan_hdr_en = GetDsL3EditTunnelV4(V, spanExtendHeaderValid_f, p_ds);
    p_sys_tunnel->xerspan_hdr_with_hash_en = GetDsL3EditTunnelV4(V, spanExtendHeaderCopyHash_f, p_ds);
    if (GetDsL3EditTunnelV4(V, encryptVxlanTunnel_f, p_ds))
    {
        p_sys_tunnel->cloud_sec_en = 1;
        p_sys_tunnel->sci_en = GetDsL3EditTunnelV4(V, dot1AeSciEn_f, p_ds);
        p_sys_tunnel->sc_index = (GetDsL3EditTunnelV4(V, ipSaIndex_f, p_ds) << 3)
                                                          + GetDsL3EditTunnelV4(V, dot1AeSaIndexLow_f, p_ds);
    }

    if (GetDsL3EditTunnelV4(V, flexTunnelEnable_f, p_ds))
    {
        p_sys_tunnel->udf_profile_id = 1;
        p_sys_tunnel->udf_profile_id = (GetDsL3EditTunnelV4(V, dontFrag_f, p_ds) << 2)
        + GetDsL3EditTunnelV4(V, flexHdrIndex_f, p_ds)
        + 1;
    }

    p_sys_tunnel->derive_dscp = GetDsL3EditTunnelV4(V, dscpRemarkMode_f, p_ds);
    if (p_sys_tunnel->derive_dscp == 1)
    {
       p_sys_tunnel->dscp = GetDsL3EditTunnelV4(V, uDscpPhb_gRaw_dscp_f, p_ds);
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        p_sys_tunnel->dscp_domain = GetDsL3EditTunnelV4(V, uDscpPhb_gPtr_dscpPhbPtr_f, p_ds);
    }

    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_GRE:
        p_sys_tunnel->gre_key = (GetDsL3EditTunnelV4(V, greKeyHigh_f, p_ds) << 16)
                                                       +  GetDsL3EditTunnelV4(V, greKeyLow_f, p_ds);
        p_sys_tunnel->gre_protocol = GetDsL3EditTunnelV4(V, greProtocol_f, p_ds);
        p_sys_tunnel->gre_flags = GetDsL3EditTunnelV4(V, greFlags_f, p_ds);
        p_sys_tunnel->gre_version = GetDsL3EditTunnelV4(V, greVersion_f, p_ds);
        p_sys_tunnel->is_gre_auto = GetDsL3EditTunnelV4(V, greAutoIdentifyProtocol_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6RD:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditTunnelV4(V, ipProtocolType_f, p_ds);
        p_sys_tunnel->tunnel6_to4_da_ipv6_prefixlen = GetDsL3EditTunnelV4(V, tunnel6To4Ipv6PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_da_ipv4_prefixlen = GetDsL3EditTunnelV4(V, tunnel6To4Ipv4PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_sa_ipv6_prefixlen = GetDsL3EditTunnelV4(V, tunnel6To4SaIpv6PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_sa_ipv4_prefixlen = GetDsL3EditTunnelV4(V, tunnel6To4SaIpv4PrefixLength_f, p_ds);
        if (p_sys_tunnel->tunnel6_to4_sa)
        {
            p_sys_tunnel->ipsa_6to4 = (GetDsL3EditTunnelV4(V, ipSa6To4High_f, p_ds) << 16)
                                                                + GetDsL3EditTunnelV4(V, ipSa6To4Low_f, p_ds);
        }
        else
        {
            p_sys_tunnel->ipsa_6to4 = (GetDsL3EditTunnelV4(V, ipSaHigh_f, p_ds) << 16)
                                                                + GetDsL3EditTunnelV4(V, ipSaLow_f, p_ds);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6TO4:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditTunnelV4(V, ipProtocolType_f, p_ds);
        p_sys_tunnel->ipsa = (GetDsL3EditTunnelV4(V, ipSaHigh_f, p_ds) << 16)
                                                                + GetDsL3EditTunnelV4(V, ipSaLow_f, p_ds);
        p_sys_tunnel->l4_dest_port = GetDsL3EditTunnelV4(V, udpDestPort_f, p_ds);
        if (p_sys_tunnel->inner_header_valid && (0 == p_sys_tunnel->ipsa_valid))
        {
            p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV4(V, udpSrcPort_f, p_ds);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_NVGRE:
        p_sys_tunnel->ipsa = (GetDsL3EditTunnelV4(V, ipSa6To4High_f, p_ds) << 16)
                                                                + GetDsL3EditTunnelV4(V, ipSa6To4Low_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_VXLAN:
        p_sys_tunnel->ipsa = (GetDsL3EditTunnelV4(V, ipSa6To4High_f, p_ds) << 16)
                                                                + GetDsL3EditTunnelV4(V, ipSa6To4Low_f, p_ds);
        p_sys_tunnel->is_evxlan = GetDsL3EditTunnelV4(V, isEvxlanTunnel_f, p_ds);
        p_sys_tunnel->evxlan_protocl_index = GetDsL3EditTunnelV4(V, protocolTypeSelIndex_f, p_ds);
        p_sys_tunnel->is_geneve = GetDsL3EditTunnelV4(V, isGeneveTunnel_f, p_ds);
        p_sys_tunnel->udp_src_port_en = GetDsL3EditTunnelV4(V, udpSrcPortCfgEn_f, p_ds);
        if (p_sys_tunnel->inner_header_valid && (0 == p_sys_tunnel->ipsa_valid))
        {
            p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV4(V, udpDestPort_f, p_ds);
        }
        p_sys_tunnel->is_vxlan_auto = GetDsL3EditTunnelV4(V, evxlanAutoIdentifyProtocol_f, p_ds);
        p_sys_tunnel->vxlan_edit_idx = GetDsL3EditTunnelV4(V, evxlanAutoIdentifyProtocol_f, p_ds)<<3
                            | GetDsL3EditTunnelV4(V, geneveAutoIdentifyProtocol_f, p_ds)<<2
                            | GetDsL3EditTunnelV4(V, protocolTypeSelIndex_f, p_ds);
        break;
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_WLAN:
        p_sys_tunnel->encrypt_en = GetDsL3EditTunnelV4(V, needCapwapEncrypt_f, p_ds);
        p_sys_tunnel->encrypt_id = GetDsL3EditTunnelV4(V, encryptKeyIndex_f, p_ds);
        p_sys_tunnel->rmac_en = GetDsL3EditTunnelV4(V, radioMacEn_f, p_ds);
        p_sys_tunnel->l4_dest_port = GetDsL3EditTunnelV4(V, udpDestPort_f, p_ds);
        if (p_sys_tunnel->inner_header_valid && (0 == p_sys_tunnel->ipsa_valid))
        {
            p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV4(V, udpSrcPort_f, p_ds);
        }
        p_sys_tunnel->bssid_bitmap = GetDsL3EditTunnelV4(V, bssidBitmap_f, p_ds);
        p_sys_tunnel->data_keepalive = GetDsL3EditTunnelV4(V, keepAlive_f, p_ds);
        break;
    default:
        break;
    }

    return CTC_E_NONE;
}
int32
sys_usw_nh_map_tunnelv6(uint8 lchip, sys_dsl3edit_tunnelv6_t* p_sys_tunnel, void *p_ds, uint32* p_offset)
{
    SetDsL3EditTunnelV6(V, udpSrcPortCfgEn_f,        p_ds,   0);
    SetDsL3EditTunnelV6(V, autoIpProtocolTypeMode_f, p_ds,   p_sys_tunnel->ip_protocol_type?0:1);
    SetDsL3EditTunnelV6(V, keepAlive_f,                    p_ds,   0);
    SetDsL3EditTunnelV6(V, udpSrcPortUseHash_f,            p_ds,   0);

    SetDsL3EditTunnelV6(V, ecnCopyMode_f,           p_ds,   p_sys_tunnel->ecn_mode);
    SetDsL3EditTunnelV6(V, discardType_f,           p_ds,   0);
    SetDsL3EditTunnelV6(V, discard_f,               p_ds,   0);
    SetDsL3EditTunnelV6(V, dsType_f,                p_ds,   p_sys_tunnel->ds_type);
    SetDsL3EditTunnelV6(V, l3RewriteType_f,         p_ds,   p_sys_tunnel->l3_rewrite_type);
    SetDsL3EditTunnelV6(V, nextEditPtrValid_f,      p_ds,   p_sys_tunnel->out_l2edit_valid);
    SetDsL3EditTunnelV6(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditTunnelV6(V, outerEditPtr_f,          p_ds,   p_sys_tunnel->out_l2edit_valid ? (p_sys_tunnel->l2edit_ptr) : 0);
    SetDsL3EditTunnelV6(V, mtuCheckEn_f,            p_ds,   p_sys_tunnel->mtu_check_en);
    SetDsL3EditTunnelV6(V, mtuSize_f,               p_ds,   p_sys_tunnel->mtu_size);
    SetDsL3EditTunnelV6(V, mapTtl_f,                p_ds,   p_sys_tunnel->map_ttl);
    SetDsL3EditTunnelV6(V, newFlowLabelMode_f,      p_ds,   p_sys_tunnel->new_flow_label_mode);
    SetDsL3EditTunnelV6(V, ttl_f,                   p_ds,   p_sys_tunnel->ttl);
    SetDsL3EditTunnelV6(V, innerHeaderValid_f,      p_ds,   p_sys_tunnel->inner_header_valid);
    SetDsL3EditTunnelV6(V, innerHeaderType_f,       p_ds,   p_sys_tunnel->inner_header_type);
    SetDsL3EditTunnelV6(V, flowLabel_f,             p_ds,   p_sys_tunnel->flow_label);
    SetDsL3EditTunnelV6(V, newFlowLabelValid_f,     p_ds,   p_sys_tunnel->new_flow_label_valid);
    SetDsL3EditTunnelV6(V, ipSaIndex_f,             p_ds,   p_sys_tunnel->ipsa_index);
    SetDsL3EditTunnelV6(A, ipDa_f,                  p_ds,   p_sys_tunnel->ipda);
    SetDsL3EditTunnelV6(V, statsPtr_f,              p_ds,   p_sys_tunnel->stats_ptr);
    SetDsL3EditTunnelV6(V, spanExtendHeaderValid_f,             p_ds,   p_sys_tunnel->xerspan_hdr_en);
    SetDsL3EditTunnelV6(V, spanExtendHeaderCopyHash_f,     p_ds,   p_sys_tunnel->xerspan_hdr_with_hash_en);
    SetDsL3EditTunnelV6(V, packetLengthType_f,           p_ds,   1);
    if (p_sys_tunnel->out_l2edit_valid && (p_sys_tunnel->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditTunnelV6(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditTunnelV6(V, outerEditPtr_f,          p_ds,   (p_sys_tunnel->l2edit_ptr-MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    if (p_sys_tunnel->cloud_sec_en)
    {
        SetDsL3EditTunnelV6(V, dot1AeSaIndexBase_f,           p_ds,   p_sys_tunnel->sc_index);
        SetDsL3EditTunnelV6(V, dot1AeSciEn_f,           p_ds,   p_sys_tunnel->sci_en);
        SetDsL3EditTunnelV6(V, encryptVxlanTunnel_f,           p_ds,   1);
    }
    else
    {
        SetDsL3EditTunnelV6(V, encryptVxlanTunnel_f,           p_ds,   0);
    }

    if (p_sys_tunnel->udf_profile_id)
    {
        SetDsL3EditTunnelV6(V, flexTunnelEnable_f,           p_ds,   1);
        SetDsL3EditTunnelV6(V, flexHdrIndex_f,           p_ds,   ((p_sys_tunnel->udf_profile_id-1)&0x7));
    }

    SetDsL3EditTunnelV6(V, dscpRemarkMode_f,        p_ds,   p_sys_tunnel->derive_dscp);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        /*assign*/
        SetDsL3EditTunnelV6(V, uDscpPhb_gRaw_dscp_f,    p_ds,   (p_sys_tunnel->tos>>2));
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        /*map*/
        SetDsL3EditTunnelV6(V, uDscpPhb_gPtr_dscpPhbPtr_f,     p_ds,   p_sys_tunnel->dscp_domain);
    }
    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_GRE:
        SetDsL3EditTunnelV6(V, greKeyHigh_f,      p_ds,   (p_sys_tunnel->gre_key >> 16));
        SetDsL3EditTunnelV6(V, greKeyLow_f,       p_ds,   (p_sys_tunnel->gre_key & 0xFFFF));
        SetDsL3EditTunnelV6(V, greProtocol_f,     p_ds,   p_sys_tunnel->gre_protocol);
        SetDsL3EditTunnelV6(V, greFlags_f,        p_ds,   p_sys_tunnel->gre_flags);
        SetDsL3EditTunnelV6(V, greVersion_f,      p_ds,   p_sys_tunnel->gre_version);
        SetDsL3EditTunnelV6(V, greAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_gre_auto);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NORMAL:
        SetDsL3EditTunnelV6(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        if (p_sys_tunnel->l4_dest_port && p_sys_tunnel->l4_src_port)
        {
            SetDsL3EditTunnelV6(V, udpDestPort_f, p_ds, p_sys_tunnel->l4_dest_port);
            SetDsL3EditTunnelV6(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NVGRE:
        SetDsL3EditTunnelV6(V, nvgreHeaderMode_f, p_ds,   1);
        SetDsL3EditTunnelV6(V, isNvgreEncaps_f,   p_ds,   1);
        SetDsL3EditTunnelV6(V, greAutoIdentifyProtocol_f,  p_ds,  1);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_VXLAN:
        SetDsL3EditTunnelV6(V, udpTunnelType_f,   p_ds,   3);

        SetDsL3EditTunnelV6(V, isEvxlanTunnel_f,   p_ds,   p_sys_tunnel->is_evxlan);
        SetDsL3EditTunnelV6(V, protocolTypeSelIndex_f,   p_ds,   p_sys_tunnel->evxlan_protocl_index);

        SetDsL3EditTunnelV6(V, isGeneveTunnel_f,   p_ds,   p_sys_tunnel->is_geneve);
        SetDsL3EditTunnelV6(V, geneveAutoIdentifyProtocol_f,   p_ds,   p_sys_tunnel->is_geneve);

        SetDsL3EditTunnelV6(V, udpSrcPortCfgEn_f,   p_ds,   p_sys_tunnel->udp_src_port_en);
        SetDsL3EditTunnelV6(V, udpDestPort_f,   p_ds,   p_sys_tunnel->l4_src_port);
        SetDsL3EditTunnelV6(V, evxlanAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_vxlan_auto);
        if(p_sys_tunnel->vxlan_edit_idx)
        {
            SetDsL3EditTunnelV6(V, evxlanAutoIdentifyProtocol_f, p_ds,   (p_sys_tunnel->vxlan_edit_idx>>3)&0x01);
            SetDsL3EditTunnelV6(V, geneveAutoIdentifyProtocol_f, p_ds,   (p_sys_tunnel->vxlan_edit_idx>>2)&0x01);
            SetDsL3EditTunnelV6(V, protocolTypeSelIndex_f, p_ds,         (p_sys_tunnel->vxlan_edit_idx)&0x03);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_WLAN:
        SetDsL3EditTunnelV6(V, needCapwapEncrypt_f, p_ds, p_sys_tunnel->encrypt_en);
        SetDsL3EditTunnelV6(V, encryptKeyIndex_f, p_ds, p_sys_tunnel->encrypt_id);
        SetDsL3EditTunnelV6(V, radioMacEn_f, p_ds, p_sys_tunnel->rmac_en);
        SetDsL3EditTunnelV6(V, isUdpLite_f, p_ds, 1);
        SetDsL3EditTunnelV6(V, udpDestPort_f, p_ds, p_sys_tunnel->l4_dest_port);
        SetDsL3EditTunnelV6(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        SetDsL3EditTunnelV6(V, bssidBitmap_f, p_ds, p_sys_tunnel->bssid_bitmap);
        SetDsL3EditTunnelV6(V, keepAlive_f, p_ds, p_sys_tunnel->data_keepalive);
        break;
    default:
        break;
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_tunnelv6(uint8 lchip, sys_dsl3edit_tunnelv6_t* p_sys_tunnel, void *p_ds)
{
    p_sys_tunnel->ecn_mode = GetDsL3EditTunnelV6(V, ecnCopyMode_f, p_ds);
    p_sys_tunnel->ds_type = GetDsL3EditTunnelV6(V, dsType_f, p_ds);
    p_sys_tunnel->l3_rewrite_type = GetDsL3EditTunnelV6(V, l3RewriteType_f, p_ds);
    p_sys_tunnel->out_l2edit_valid = GetDsL3EditTunnelV6(V, nextEditPtrValid_f, p_ds);
    p_sys_tunnel->l2edit_ptr = GetDsL3EditTunnelV6(V, outerEditPtr_f, p_ds);
    p_sys_tunnel->mtu_check_en = GetDsL3EditTunnelV6(V, mtuCheckEn_f, p_ds);
    p_sys_tunnel->mtu_size = GetDsL3EditTunnelV6(V, mtuSize_f, p_ds);
    p_sys_tunnel->map_ttl = GetDsL3EditTunnelV6(V, mapTtl_f, p_ds);
    p_sys_tunnel->new_flow_label_mode = GetDsL3EditTunnelV6(V, newFlowLabelMode_f, p_ds);
    p_sys_tunnel->ttl = GetDsL3EditTunnelV6(V, ttl_f, p_ds);
    p_sys_tunnel->inner_header_valid = GetDsL3EditTunnelV6(V, innerHeaderValid_f, p_ds);
    p_sys_tunnel->inner_header_type = GetDsL3EditTunnelV6(V, innerHeaderType_f, p_ds);
    p_sys_tunnel->flow_label = GetDsL3EditTunnelV6(V, flowLabel_f, p_ds);
    p_sys_tunnel->new_flow_label_valid = GetDsL3EditTunnelV6(V, newFlowLabelValid_f, p_ds);
    p_sys_tunnel->ipsa_index = GetDsL3EditTunnelV6(V, ipSaIndex_f, p_ds);
    GetDsL3EditTunnelV6(A, ipDa_f, p_ds,   p_sys_tunnel->ipda);
    p_sys_tunnel->stats_ptr = GetDsL3EditTunnelV6(V, statsPtr_f, p_ds);
    p_sys_tunnel->xerspan_hdr_en = GetDsL3EditTunnelV6(V, spanExtendHeaderValid_f, p_ds);
    p_sys_tunnel->xerspan_hdr_with_hash_en = GetDsL3EditTunnelV6(V, spanExtendHeaderCopyHash_f, p_ds);

    if (GetDsL3EditTunnelV6(V, encryptVxlanTunnel_f, p_ds))
    {
        p_sys_tunnel->cloud_sec_en = 1;
        p_sys_tunnel->sc_index = GetDsL3EditTunnelV6(V, dot1AeSaIndexBase_f, p_ds);
        p_sys_tunnel->sci_en = GetDsL3EditTunnelV6(V, dot1AeSciEn_f, p_ds);
    }
    if (GetDsL3EditTunnelV6(V, flexTunnelEnable_f, p_ds))
    {
        p_sys_tunnel->udf_profile_id = 1;
        p_sys_tunnel->udf_profile_id = GetDsL3EditTunnelV6(V, flexHdrIndex_f, p_ds) + 1;
    }
    p_sys_tunnel->derive_dscp = GetDsL3EditTunnelV6(V, dscpRemarkMode_f, p_ds);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        p_sys_tunnel->tos = GetDsL3EditTunnelV6(V, uDscpPhb_gRaw_dscp_f, p_ds) << 2;
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        p_sys_tunnel->dscp_domain = GetDsL3EditTunnelV6(V, uDscpPhb_gPtr_dscpPhbPtr_f, p_ds);
    }
    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_GRE:
        p_sys_tunnel->gre_key = (GetDsL3EditTunnelV6(V, greKeyHigh_f, p_ds) << 16)
                                                        + GetDsL3EditTunnelV6(V, greKeyLow_f, p_ds);
        p_sys_tunnel->gre_protocol = GetDsL3EditTunnelV6(V, greProtocol_f, p_ds);
        p_sys_tunnel->gre_flags = GetDsL3EditTunnelV6(V, greFlags_f, p_ds);
        p_sys_tunnel->gre_version = GetDsL3EditTunnelV6(V, greVersion_f, p_ds);
        p_sys_tunnel->is_gre_auto = GetDsL3EditTunnelV6(V, greAutoIdentifyProtocol_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NORMAL:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditTunnelV6(V, ipProtocolType_f, p_ds);
        p_sys_tunnel->l4_dest_port = GetDsL3EditTunnelV6(V, udpDestPort_f, p_ds);
        p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV6(V, udpSrcPort_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NVGRE:
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_VXLAN:
        p_sys_tunnel->is_evxlan = GetDsL3EditTunnelV6(V, isEvxlanTunnel_f, p_ds);
        p_sys_tunnel->evxlan_protocl_index = GetDsL3EditTunnelV6(V, protocolTypeSelIndex_f, p_ds);
        p_sys_tunnel->is_geneve = GetDsL3EditTunnelV6(V, isGeneveTunnel_f, p_ds);
        p_sys_tunnel->udp_src_port_en = GetDsL3EditTunnelV6(V, udpSrcPortCfgEn_f, p_ds);
        p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV6(V, udpDestPort_f, p_ds);
        p_sys_tunnel->is_vxlan_auto = GetDsL3EditTunnelV6(V, evxlanAutoIdentifyProtocol_f, p_ds);
        p_sys_tunnel->vxlan_edit_idx = GetDsL3EditTunnelV6(V, evxlanAutoIdentifyProtocol_f, p_ds)<<3
                            | GetDsL3EditTunnelV6(V, geneveAutoIdentifyProtocol_f, p_ds)<<2
                            | GetDsL3EditTunnelV6(V, protocolTypeSelIndex_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_WLAN:
        p_sys_tunnel->encrypt_en = GetDsL3EditTunnelV6(V, needCapwapEncrypt_f, p_ds);
        p_sys_tunnel->encrypt_id = GetDsL3EditTunnelV6(V, encryptKeyIndex_f, p_ds);
        p_sys_tunnel->rmac_en = GetDsL3EditTunnelV6(V, radioMacEn_f, p_ds);
        p_sys_tunnel->l4_dest_port = GetDsL3EditTunnelV6(V, udpDestPort_f, p_ds);
        p_sys_tunnel->l4_src_port = GetDsL3EditTunnelV6(V, udpSrcPort_f, p_ds);
        p_sys_tunnel->bssid_bitmap = GetDsL3EditTunnelV6(V, bssidBitmap_f, p_ds);
        p_sys_tunnel->data_keepalive = GetDsL3EditTunnelV6(V, keepAlive_f, p_ds);
        break;
    default:
        break;
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_nat4w(uint8 lchip, sys_dsl3edit_nat4w_t* p_sys_nat, void *p_ds, uint32* p_offset)
{
    SetDsL3EditNat3W(V, discardType_f,           p_ds,   0);
    SetDsL3EditNat3W(V, discard_f,               p_ds,   0);
    SetDsL3EditNat3W(V, dsType_f,                p_ds,   p_sys_nat->ds_type);
    SetDsL3EditNat3W(V, l3RewriteType_f,         p_ds,   p_sys_nat->l3_rewrite_type);
    SetDsL3EditNat3W(V, nextEditPtrValid_f,      p_ds,   p_sys_nat->out_l2edit_valid);
    SetDsL3EditNat3W(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditNat3W(V, outerEditPtr_f,          p_ds,   p_sys_nat->l2edit_ptr);
    SetDsL3EditNat3W(V, ipDa_f,                  p_ds,   p_sys_nat->ip);
    SetDsL3EditNat3W(V, ipDaPrefixLength_f,      p_ds,   p_sys_nat->ip_da_prefix_length);
    SetDsL3EditNat3W(V, ipv4EmbededMode_f,       p_ds,   p_sys_nat->ipv4_embeded_mode);
    SetDsL3EditNat3W(V, replaceIpDa_f,           p_ds,   p_sys_nat->replace_ip_da);
    SetDsL3EditNat3W(V, l4DestPort_f,            p_ds,   p_sys_nat->l4_port);
    SetDsL3EditNat3W(V, replaceL4DestPort_f,     p_ds,   p_sys_nat->replace_l4_dest_port);
    if (p_sys_nat->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditNat3W(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditNat3W(V, outerEditPtr_f,          p_ds,   (p_sys_nat->l2edit_ptr-MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_nat4w(uint8 lchip, sys_dsl3edit_nat4w_t* p_sys_nat, void *p_ds)
{
    p_sys_nat->ds_type = GetDsL3EditNat3W(V, dsType_f, p_ds);
    p_sys_nat->l3_rewrite_type = GetDsL3EditNat3W(V, l3RewriteType_f, p_ds);
    p_sys_nat->out_l2edit_valid = GetDsL3EditNat3W(V, nextEditPtrValid_f, p_ds);
    p_sys_nat->l2edit_ptr = GetDsL3EditNat3W(V, outerEditPtr_f, p_ds);
    p_sys_nat->ip = GetDsL3EditNat3W(V, ipDa_f, p_ds);
    p_sys_nat->ip_da_prefix_length = GetDsL3EditNat3W(V, ipDaPrefixLength_f, p_ds);
    p_sys_nat->ipv4_embeded_mode = GetDsL3EditNat3W(V, ipv4EmbededMode_f, p_ds);
    p_sys_nat->replace_ip_da = GetDsL3EditNat3W(V, replaceIpDa_f, p_ds);
    p_sys_nat->l4_port = GetDsL3EditNat3W(V, l4DestPort_f, p_ds);
    p_sys_nat->replace_l4_dest_port = GetDsL3EditNat3W(V, replaceL4DestPort_f, p_ds);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_nat8w(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds, uint32* p_offset)
{
    uint32 ipda[4] = {0};
    SetDsL3EditNat6W(V, l4DestPort_f,            p_ds,   p_sys_nat->l4_dest_port);
    SetDsL3EditNat6W(V, replaceIpDa_f,           p_ds,   p_sys_nat->replace_ip_da);
    SetDsL3EditNat6W(V, replaceL4DestPort_f,     p_ds,   p_sys_nat->replace_l4_dest_port);
    SetDsL3EditNat6W(V, discardType_f,           p_ds,   0);
    SetDsL3EditNat6W(V, discard_f,               p_ds,   0);
    SetDsL3EditNat6W(V, dsType_f,                p_ds,   p_sys_nat->ds_type);
    SetDsL3EditNat6W(V, l3RewriteType_f,         p_ds,   p_sys_nat->l3_rewrite_type);
    SetDsL3EditNat6W(V, nextEditPtrValid_f,      p_ds,   0);
    SetDsL3EditNat6W(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditNat6W(V, outerEditPtr_f,          p_ds,   0);
    SetDsL3EditNat6W(V, ipDaPrefixLength_f,      p_ds,   p_sys_nat->ip_da_prefix_length);
    SetDsL3EditNat6W(V, ipv4EmbededMode_f,       p_ds,   p_sys_nat->ipv4_embeded_mode);
    SetDsL3EditNat6W(A, ipDa_f,       p_ds,  p_sys_nat->ipda);
    ipda[0] = p_sys_nat->ipda[1] >> 12;
    ipda[0] |= (p_sys_nat->ipda[2] << 20);
    ipda[1] = p_sys_nat->ipda[2] >> 12;
    ipda[1] |= (p_sys_nat->ipda[3] << 20);
    ipda[2] = p_sys_nat->ipda[3] >> 12;
    SetDsL3EditNat6W(A, ipDaHigh_f,       p_ds,  ipda);
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_nat8w(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds)
{
    uint32 ipda[4] = {0};
    p_sys_nat->l4_dest_port = GetDsL3EditNat6W(V, l4DestPort_f, p_ds);
    p_sys_nat->replace_ip_da = GetDsL3EditNat6W(V, replaceIpDa_f, p_ds);
    p_sys_nat->replace_l4_dest_port = GetDsL3EditNat6W(V, replaceL4DestPort_f, p_ds);
    p_sys_nat->ds_type = GetDsL3EditNat6W(V, dsType_f, p_ds);
    p_sys_nat->l3_rewrite_type = GetDsL3EditNat6W(V, l3RewriteType_f, p_ds);
    p_sys_nat->ip_da_prefix_length = GetDsL3EditNat6W(V, ipDaPrefixLength_f, p_ds);
    p_sys_nat->ipv4_embeded_mode = GetDsL3EditNat6W(V, ipv4EmbededMode_f, p_ds);
    GetDsL3EditNat6W(A, ipDa_f, p_ds,  p_sys_nat->ipda);
    GetDsL3EditNat6W(A, ipDaHigh_f, p_ds,  ipda);
    p_sys_nat->ipda[1] |= ipda[0] << 12;
    p_sys_nat->ipda[2] = ipda[0] >> 20;
    p_sys_nat->ipda[2] |= ipda[1] << 12;
    p_sys_nat->ipda[3] = ipda[1] >> 20;
    p_sys_nat->ipda[3] |= ipda[2] << 12;
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_trill(uint8 lchip, sys_dsl3edit_trill_t* p_sys_trill, void *p_ds, uint32* p_offset)
{
    SetDsL3EditTrill(V, discard_f,            p_ds, 0);
    SetDsL3EditTrill(V, discardType_f,        p_ds, 0);
    SetDsL3EditTrill(V, nextEditPtrValid_f,   p_ds, 0);
    SetDsL3EditTrill(V, outerEditPtr_f,       p_ds, 0);
    SetDsL3EditTrill(V, outerEditPtrType_f,   p_ds, 0);
    SetDsL3EditTrill(V, statsPtr_f,           p_ds, 0);
    SetDsL3EditTrill(V, l3RewriteType_f,         p_ds,   p_sys_trill->l3_rewrite_type);
    SetDsL3EditTrill(V, l3EditType_f,            p_ds,   p_sys_trill->l3_rewrite_type);
    SetDsL3EditTrill(V, ingressNickname_f,       p_ds,   p_sys_trill->ingress_nickname);
    SetDsL3EditTrill(V, egressNickname_f,        p_ds,   p_sys_trill->egress_nickname);
    SetDsL3EditTrill(V, hopCount_f,              p_ds,   p_sys_trill->ttl);
    SetDsL3EditTrill(V, mtuCheckEn_f,            p_ds,   p_sys_trill->mtu_check_en);
    SetDsL3EditTrill(V, mtuSize_f,               p_ds,   p_sys_trill->mtu_size);
    SetDsL3EditTrill(V, statsPtr_f,              p_ds,   p_sys_trill->stats_ptr);
    return CTC_E_NONE;
}



int32
sys_usw_nh_map_ecmp_group(uint8 lchip, sys_dsecmp_group_t* p_sys_ecmp_group, void *p_ds, uint32* p_offset)
{
    uint32 value = 0;
    SetDsEcmpGroup(V, ecmpLinkSelfHealingEn_f,              p_ds,   p_sys_ecmp_group->failover_en);
    SetDsEcmpGroup(V, memberNum_f,          p_ds,   p_sys_ecmp_group->member_num);
    SetDsEcmpGroup(V, memberPtrBase_f,      p_ds,   p_sys_ecmp_group->member_base);
    SetDsEcmpGroup(V, statsEn_f,            p_ds,   p_sys_ecmp_group->stats_valid);
    SetDsEcmpGroup(V, rrProfileId_f,            p_ds,   p_sys_ecmp_group->rr_profile_id);
    SetDsEcmpGroup(V, antFlowEn_f,            p_ds,   p_sys_ecmp_group->ant_flow_en);
    SetDsEcmpGroup(V, antFlowTableBase_f,            p_ds,   p_sys_ecmp_group->ant_flow_base);
    SetDsEcmpGroup(V, antFlowNum_f,            p_ds,   p_sys_ecmp_group->ant_flow_num);
    if (p_sys_ecmp_group->resilient_hash_en)
    {
        value = 3;
    }
    else if (p_sys_ecmp_group->rr_en)
    {
        value = 2;
    }
    else if (p_sys_ecmp_group->dlb_en)
    {
        value = 1;
    }
    SetDsEcmpGroup(V, runningMode_f,            p_ds,   value);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_unecmp_group(uint8 lchip, sys_dsecmp_group_t* p_sys_ecmp_group, void *p_ds)
{
    uint32 value = 0;
    p_sys_ecmp_group->failover_en   = GetDsEcmpGroup(V, ecmpLinkSelfHealingEn_f, p_ds);
    p_sys_ecmp_group->member_num    = GetDsEcmpGroup(V, memberNum_f, p_ds);
    p_sys_ecmp_group->member_base   = GetDsEcmpGroup(V, memberPtrBase_f, p_ds);
    p_sys_ecmp_group->stats_valid   = GetDsEcmpGroup(V, statsEn_f, p_ds);
    p_sys_ecmp_group->rr_profile_id = GetDsEcmpGroup(V, rrProfileId_f, p_ds);
    p_sys_ecmp_group->ant_flow_en   = GetDsEcmpGroup(V, antFlowEn_f, p_ds);
    p_sys_ecmp_group->ant_flow_base = GetDsEcmpGroup(V, antFlowTableBase_f, p_ds);
    p_sys_ecmp_group->ant_flow_num  = GetDsEcmpGroup(V, antFlowNum_f, p_ds);
    value = GetDsEcmpGroup(V, runningMode_f, p_ds);
    if (3 == value)
    {
        p_sys_ecmp_group->resilient_hash_en = 1;
    }
    else if (2 == value)
    {
        p_sys_ecmp_group->rr_en = 1;
    }
    else if (1 == value)
    {
        p_sys_ecmp_group->dlb_en = 1;
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_ecmp_member(uint8 lchip, sys_dsecmp_member_t* p_sys_ecmp_member, void *p_ds, uint32* p_offset)
{
    uint8 i = 0;
    uint8 step = 0;
    step = DsEcmpMember_array_1_valid_f - DsEcmpMember_array_0_valid_f;
    for (i = 0; i < 4; i++)
    {
        SetDsEcmpMember(V, array_0_valid_f + step*i,         p_ds,   p_sys_ecmp_member->info[i].valid);

        SetDsEcmpMember(V, array_0_logicDestPort_f + step*i, p_ds,   p_sys_ecmp_member->info[i].logic_dest_port);
        SetDsEcmpMember(V, array_0_statsPtr_f + step*i,      p_ds,   p_sys_ecmp_member->info[i].stats_ptr);

        if (p_sys_ecmp_member->info[i].ecmp_gid != 0 || (DRV_FROM_AT(lchip) && p_sys_ecmp_member->info[i].nexthop_ptr != 0))
        {
            SetDsEcmpMember(V, array_0_ecmpGroupId_f + step * i, p_ds, p_sys_ecmp_member->info[i].ecmp_gid);
            SetDsEcmpMember(V, array_0_u1_gEcmp_bypassIngressEdit_f + step * i, p_ds, p_sys_ecmp_member->info[i].bypass_igs_edit);
            SetDsEcmpMember(V, array_0_u1_gEcmp_nextHopExt_f + step * i, p_ds, p_sys_ecmp_member->info[i].nexthop_ext);
            SetDsEcmpMember(V, array_0_u1_gEcmp_nextHopPtr_f + step * i, p_ds, p_sys_ecmp_member->info[i].nexthop_ptr);
            SetDsEcmpMember(V, array_0_isEcmp_f + step * i, p_ds, 1);
        }
        else
        {
            SetDsEcmpMember(V, array_0_dsFwdPtr_f + step * i, p_ds, p_sys_ecmp_member->info[i].dsfwdptr);
            SetDsEcmpMember(V, array_0_destChannel_f + step * i, p_ds, p_sys_ecmp_member->info[i].dest_channel);
            SetDsEcmpMember(V, array_0_isEcmp_f + step * i, p_ds, 0);
        }
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_ecmp_member(uint8 lchip, sys_dsecmp_member_t* p_sys_ecmp_member, void *p_ds)
{
    uint8 i = 0;
    uint8 step = 0;

    step = DsEcmpMember_array_1_valid_f - DsEcmpMember_array_0_valid_f;
    for (i = 0; i < 4; i++)
    {
        p_sys_ecmp_member->info[i].valid           = GetDsEcmpMember(V, array_0_valid_f + step*i,         p_ds);
        p_sys_ecmp_member->info[i].logic_dest_port = GetDsEcmpMember(V, array_0_logicDestPort_f + step*i, p_ds);
        //p_sys_ecmp_member->info[i].stats_ptr       = GetDsEcmpMember(V, array_0_statsPtr_f + step*i,      p_ds);

        if (0 == GetDsEcmpMember(V, array_0_isEcmp_f + step*i,        p_ds))
        {
            p_sys_ecmp_member->info[i].dsfwdptr = GetDsEcmpMember(V, array_0_dsFwdPtr_f + step*i,      p_ds);
            p_sys_ecmp_member->info[i].dest_channel = GetDsEcmpMember(V, array_0_destChannel_f + step*i,   p_ds);
        }
        else
        {
            p_sys_ecmp_member->info[i].ecmp_gid = GetDsEcmpMember(V, array_0_ecmpGroupId_f + step*i,   p_ds);
            p_sys_ecmp_member->info[i].nexthop_ptr = GetDsEcmpMember(V, array_0_u1_gEcmp_nextHopPtr_f + step*i,   p_ds);
            p_sys_ecmp_member->info[i].nexthop_ext = GetDsEcmpMember(V, array_0_u1_gEcmp_nextHopExt_f + step*i,   p_ds);
            p_sys_ecmp_member->info[i].bypass_igs_edit = GetDsEcmpMember(V, array_0_u1_gEcmp_bypassIngressEdit_f + step*i,   p_ds);
        }
    }

    return CTC_E_NONE;
}


int32
sys_usw_nh_map_ecmp_rr_count(uint8 lchip, sys_dsecmp_rr_t* p_sys_ecmp_rr, void *p_ds, uint32* p_offset)
{
    SetDsEcmpRrCount(V, randomRrEn_f,   p_ds,   p_sys_ecmp_rr->random_rr_en);
    SetDsEcmpRrCount(V, memberNum_f,    p_ds,   p_sys_ecmp_rr->member_num);
    return CTC_E_NONE;
}

#define FROM_TMM_START

 void
_sys_usw_nh_map_ether_type(uint8 lchip, uint16* ether_type, uint8* profile_id, uint8 type2id)
{
    uint16 loop = 0;
    uint16 ether_type_pool[15] = {/*refer to EpeL2EtherTypeCtl*/
        0x0000, 0x0800, 0x0800, 0x86DD,
        0x8847, 0x8848, 0x0806, 0x8906,
        0x22F3, 0x8902, 0x8809, 0x894F,
        0x88F7, 0x88E5, 0x88B7
    };

    if (0 == type2id)
    {
        *ether_type = ether_type_pool[*profile_id];
        return;
    }
    do {
        if (*ether_type == ether_type_pool[loop])
        {
            *profile_id = loop;
            return;
        }
    }while(++loop < 15);
}

int32
sys_usw_nh_map_l2edit_inner_autoeth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;
    uint8  ether_type_prof_id = 0;
    mac_addr_t mac_zero = {0};

    SetDsL2EditAutoEth1X(V, discardType_f,           p_ds,  0);
    SetDsL2EditAutoEth1X(V, discard_f,               p_ds,  0);
    SetDsL2EditAutoEth1X(V, dsType_f,                p_ds,  SYS_NH_DS_TYPE_L2EDIT);
    SetDsL2EditAutoEth1X(V, l2EditType_f,            p_ds,  p_sys_l2edit->l2_rewrite_type);

    SetDsL2EditAutoEth1X(V, deriveMcastMacForIp_f,            p_ds,  p_sys_l2edit->derive_mcast_mac_for_ip);
    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->mac_da);
    SetDsL2EditAutoEth1X(A, macDa_f,                 p_ds,  mac);

    if (0 != sal_memcmp(p_sys_l2edit->mac_da, mac_zero, 6))
    {
        SetDsL2EditAutoEth1X(V, macDaEn_f,     p_ds, 1 );
        SetDsL2EditAutoEth1X(V, macDaRewriteEn_f,     p_ds, 1);
    }
    if (p_sys_l2edit->derive_mcast_mac_for_ip)
    {
        SetDsL2EditAutoEth1X(V, macDaRewriteEn_f,     p_ds, 1);
    }

    if (p_sys_l2edit->update_mac_sa)
    {
        SetDsL2EditAutoEth1X(V, macSaRewriteEn_f,     p_ds, 1);
    }

    if (p_sys_l2edit->is_8w)
    {
        if (0 != sal_memcmp(p_sys_l2edit->mac_sa, mac_zero, 6))
        {
            SetDsL2EditAutoEth2X(V, macSaEn_f,     p_ds, 1);
        }
        SYS_USW_SET_HW_MAC(mac, p_sys_l2edit->mac_sa);
        SetDsL2EditAutoEth2X(A, macSa_f,                 p_ds,  mac);
        SetDsL2EditAutoEth2X(V, etherType_f,             p_ds,  p_sys_l2edit->ether_type);
        SetDsL2EditAutoEth2X(V, etherTypeValid_f,        p_ds,  p_sys_l2edit->ether_type? 1 : 0);
    }
    else if (p_sys_l2edit->ether_type)
    {
        _sys_usw_nh_map_ether_type(lchip, &p_sys_l2edit->ether_type, &ether_type_prof_id, TRUE);
        SetDsL2EditAutoEth1X(V, etherTypeProfId_f,      p_ds, ether_type_prof_id);
        SetDsL2EditAutoEth1X(V, etherTypeProfIdValid_f, p_ds, 1);
        SetDsL2EditAutoEth1X(V, etherTypeRewriteEn_f, p_ds, 1);
    }
    SetDsL2EditAutoEth1X(V, xEditPtr_f,           p_ds,  p_sys_l2edit->xeditptr);

    if (p_sys_l2edit->use_port_mac)
    {
        SetDsL2EditAutoEth2X(V, ecmpTunnelMacDaEn_f,     p_ds, 1);
        SetDsL2EditAutoEth2X(V, macDaRewriteEn_f,     p_ds, 1);
        SetDsL2EditAutoEth2X(V, interfaceVlanEn_f, p_ds, 1);
    }

    return CTC_E_NONE;
}
int32
sys_usw_nh_unmap_l2edit_inner_autoeth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds)
{
    hw_mac_addr_t mac;
    uint8  ether_type_prof_id = 0;

    p_sys_l2edit->derive_mcast_mac_for_ip = GetDsL2EditAutoEth1X(V, deriveMcastMacForIp_f,            p_ds)?1:0;

    if (GetDsL2EditAutoEth1X(V, macDaEn_f,     p_ds))
    {
        GetDsL2EditAutoEth1X(A, macDa_f,                 p_ds,  mac);
        SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_da, mac);
    }

    p_sys_l2edit->update_mac_sa = GetDsL2EditAutoEth1X(V, macSaRewriteEn_f, p_ds)?1:0;
    p_sys_l2edit->l2_rewrite_type = GetDsL2EditAutoEth1X(V, l2EditType_f, p_ds);
    if(DRV_ENUM(DRV_L2EDITTYPE_AUTOETH2X) == p_sys_l2edit->l2_rewrite_type)
    {
        if (GetDsL2EditAutoEth2X(V, macSaEn_f,     p_ds))
        {
            GetDsL2EditAutoEth2X(A, macSa_f,     p_ds, mac);
            SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_sa, mac);
        }
        p_sys_l2edit->ether_type = GetDsL2EditAutoEth2X(V, etherType_f,             p_ds);
    }
    else if (GetDsL2EditAutoEth1X(V, etherTypeProfIdValid_f, p_ds))
    {
        ether_type_prof_id = GetDsL2EditAutoEth1X(V, etherTypeProfId_f,      p_ds);
        _sys_usw_nh_map_ether_type(lchip, &p_sys_l2edit->ether_type, &ether_type_prof_id, 0);
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l2edit_addeth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;
    uint8  ether_type_prof_id = 0;
    uint32 macda_en = 0;

    if (DRV_ENUM(DRV_L2EDITTYPE_AUTOETH2X) == p_sys_l2edit->l2_rewrite_type
         || DRV_ENUM(DRV_L2EDITTYPE_AUTOETH1X) == p_sys_l2edit->l2_rewrite_type)
    {
        return sys_usw_nh_map_l2edit_inner_autoeth(lchip, p_sys_l2edit, p_ds, p_offset);
    }
    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->mac_da)

    if ((mac[0] == 0) && (mac[1] == 0))
    {
        macda_en = 0;
    }
    else
    {
        if (p_sys_l2edit->is_dot11 && p_sys_l2edit->derive_mcast_mac_for_trill && p_sys_l2edit->derive_mcast_mac_for_mpls)
        {
            /*wds: mac da means dest bssid, new mac da retrive from original packet, only used for splic l2 */
            macda_en = 0;
        }
        else
        {
            macda_en = 1;
        }
    }


    SetDsL2EditAddEth1X(V, discardType_f,           p_ds,  0);
    SetDsL2EditAddEth1X(V, discard_f,               p_ds,  0);
    SetDsL2EditAddEth1X(V, dsType_f,                p_ds,  p_sys_l2edit->ds_type);
    SetDsL2EditAddEth1X(V, l2EditType_f,         p_ds,  p_sys_l2edit->l2_rewrite_type);
    SetDsL2EditAddEth1X(V, mapCos_f,                p_ds,  p_sys_l2edit->map_cos);
    SetDsL2EditAddEth1X(V, portMacSaEn_f,           p_ds,  0);
    SetDsL2EditAddEth1X(V, deriveMacFromLabel_f,    p_ds,  p_sys_l2edit->derive_mac_from_label);
    SetDsL2EditAddEth1X(V, macDaEn_f,               p_ds,  0);

    if ((p_sys_l2edit->output_cvid || p_sys_l2edit->output_cvid_valid)
       && (0 == p_sys_l2edit->is_8w) && (0 == p_sys_l2edit->output_vid) && (0 == p_sys_l2edit->output_vid_valid))
    {
        SetDsL2EditAddEth1X(V, outputVlanIdValid_f,     p_ds,  1);
        SetDsL2EditAddEth1X(V, outputVlanId_f,  p_ds,  p_sys_l2edit->output_cvid);
        SetDsL2EditAddEth1X(V, outputVlanIdIsSvlan_f,   p_ds,  0);
        SetDsL2EditAddEth1X(V, overwriteIntfCvlanId_f,     p_ds,  1);
    }
    else if(p_sys_l2edit->output_vid || p_sys_l2edit->output_vid_valid)
    {
        SetDsL2EditAddEth1X(V, overwriteIntfSvlanId_f,   p_ds,  1);
        SetDsL2EditAddEth1X(V, outputVlanIdIsSvlan_f,   p_ds,  1);
        SetDsL2EditAddEth1X(V, outputVlanIdValid_f,     p_ds,  1);
        SetDsL2EditAddEth1X(V, outputVlanId_f,          p_ds,  p_sys_l2edit->output_vid);
    }
    else
    {
        SetDsL2EditAddEth1X(V, outputVlanId_f,          p_ds,  0xFFF);
    }
    SetDsL2EditAddEth1X(V, macDaEn_f,                p_ds,  macda_en);
    SetDsL2EditAddEth1X(A, macDa_f,                p_ds,  mac);
    SetDsL2EditAddEth1X(V, deriveFcoeMacSa_f,       p_ds,  0);
    SetDsL2EditAddEth1X(V, deriveMcastMacForTrill_f,p_ds,  p_sys_l2edit->derive_mcast_mac_for_trill);
    SetDsL2EditAddEth1X(V, deriveMcastMacForMpls_f, p_ds,  p_sys_l2edit->derive_mcast_mac_for_mpls);
    SetDsL2EditAddEth1X(V, deriveMcastMacForIp_f,   p_ds,  p_sys_l2edit->derive_mcast_mac_for_ip);
    SetDsL2EditAddEth1X(V, deriveFcoeMac_f,         p_ds,  p_sys_l2edit->fpma);
    SetDsL2EditAddEth1X(V, systemRouterMac_f,       p_ds,  0);
    SetDsL2EditAddEth1X(V, xEditPtr_f,              p_ds,  p_sys_l2edit->xeditptr);

    if (p_sys_l2edit->is_8w)
    {
        SetDsL2EditAddEth2X(V, cosPhbPtr_f,                    p_ds,  p_sys_l2edit->cos_domain);
        SetDsL2EditAddEth2X(V, fcoeOverTrillMacSaEn_f,         p_ds,  0);

        if (p_sys_l2edit->use_port_mac)
        {
            SetDsL2EditAddEth1X(V, outputVlanId_f,          p_ds,  0);
            SetDsL2EditAddEth2X(V, ecmpTunnelMacDaEn_f ,    p_ds,  1);
        }

        if(p_sys_l2edit->update_mac_sa)
        {
            SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->mac_sa);
            SetDsL2EditAddEth2X(A, macSa_f,     p_ds,  mac);
            SetDsL2EditAddEth2X(V, macSaEn_f,  p_ds,  1);
        }

        if (p_sys_l2edit->ether_type)
        {
            SetDsL2EditAddEth2X(V, etherTypeRewriteValid_f,  p_ds,  1);
            SetDsL2EditAddEth2X(V, etherType_f,  p_ds,  p_sys_l2edit->ether_type);
        }

        if (p_sys_l2edit->output_cvid || p_sys_l2edit->output_cvid_valid)
        {
            SetDsL2EditAddEth2X(V, outputCvlanIdValid_f,     p_ds,  1);
            SetDsL2EditAddEth2X(V, outputCvlanId_f,  p_ds,  p_sys_l2edit->output_cvid);
            SetDsL2EditAddEth2X(V, overwriteIntfCvlanId_f,     p_ds,  1);
        }

    }
    else if (p_sys_l2edit->ether_type)
    {
        _sys_usw_nh_map_ether_type(lchip, &p_sys_l2edit->ether_type, &ether_type_prof_id, TRUE);
        SetDsL2EditAddEth1X(V, etherTypeProfId_f,      p_ds, ether_type_prof_id);
        SetDsL2EditAddEth1X(V, etherTypeProfIdValid_f, p_ds, 1);
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_l2edit_addeth(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds)
{
    uint8 ether_type_prof_id = 0;
    hw_mac_addr_t mac = {0};

    if (DRV_ENUM(DRV_L2EDITTYPE_AUTOETH2X) == p_sys_l2edit->l2_rewrite_type
         || DRV_ENUM(DRV_L2EDITTYPE_AUTOETH1X) == p_sys_l2edit->l2_rewrite_type)
    {
        return sys_usw_nh_unmap_l2edit_inner_autoeth(lchip, p_sys_l2edit, p_ds);
    }
    if (GetDsL2EditAddEth1X(V, macDaEn_f,  p_ds))
    {
        GetDsL2EditAddEth1X(A, macDa_f, p_ds,  mac);
        SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_da, mac);
    }
    if (GetDsL2EditAddEth1X(V, outputVlanIdValid_f, p_ds))
    {
        if (GetDsL2EditAddEth1X(V, outputVlanIdIsSvlan_f, p_ds))
        {
            p_sys_l2edit->output_vid = GetDsL2EditAddEth1X(V, outputVlanId_f, p_ds);
        }
        else
        {
            p_sys_l2edit->output_cvid = GetDsL2EditAddEth1X(V, outputVlanId_f, p_ds);
        }
    }

    p_sys_l2edit->l2_rewrite_type = GetDsL2EditAddEth1X(V, l2EditType_f, p_ds);
    if ((DRV_ENUM(DRV_L2EDITTYPE_ADDETH2X) == p_sys_l2edit->l2_rewrite_type)
        ||(DRV_ENUM(DRV_L2EDITTYPE_RWETH2X) == p_sys_l2edit->l2_rewrite_type))
    {
        p_sys_l2edit->is_8w = 1;
        if (GetDsL2EditAddEth2X(V, macSaEn_f,  p_ds))
        {
            p_sys_l2edit->update_mac_sa = 1;
            GetDsL2EditAddEth2X(A, macSa_f, p_ds,  mac);
            SYS_USW_SET_USER_MAC(p_sys_l2edit->mac_sa, mac);
        }

        if (GetDsL2EditAddEth2X(V, outputCvlanIdValid_f, p_ds))
        {
            p_sys_l2edit->output_cvid = GetDsL2EditAddEth2X(V, outputCvlanId_f, p_ds);
        }

        p_sys_l2edit->ether_type = GetDsL2EditAddEth2X(V, etherType_f,  p_ds);
    }
    else if (GetDsL2EditAddEth1X(V, etherTypeProfIdValid_f,  p_ds))
    {
        ether_type_prof_id = GetDsL2EditAddEth1X(V, etherTypeProfId_f, p_ds);
        _sys_usw_nh_map_ether_type(lchip, &p_sys_l2edit->ether_type, &ether_type_prof_id, FALSE);
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_l2edit_rweth2x(uint8 lchip, sys_dsl2edit_of6w_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    hw_mac_addr_t mac;

    SetDsL2EditRwEth2X(V, discardType_f,           p_ds,  0);
    SetDsL2EditRwEth2X(V, discard_f,               p_ds,  0);
    SetDsL2EditRwEth2X(V, dsType_f,                p_ds,  SYS_NH_DS_TYPE_L2EDIT);
    SetDsL2EditRwEth2X(V, l2EditType_f,           p_ds,  DRV_ENUM(DRV_L2EDITTYPE_RWETH2X));

    SYS_USW_SET_HW_MAC(mac,  p_sys_l2edit->p_flex_edit->mac_da);
    SetDsL2EditRwEth2X(A, macDa_f,                 p_ds,  mac);
    SYS_USW_SET_HW_MAC(mac, p_sys_l2edit->p_flex_edit->mac_sa);
    SetDsL2EditRwEth2X(A, macSa_f,                 p_ds,  mac);
    SetDsL2EditRwEth2X(V, etherType_f,     p_ds, p_sys_l2edit->p_flex_edit->ether_type);

    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_MACDA))
    {
        SetDsL2EditRwEth2X(V, macDaCopySrc_f,           p_ds,  1);
        SetDsL2EditRwEth2X(V, macSaCopyDst_f,           p_ds,  1);
        SetDsL2EditRwEth2X(V, macDaRewriteEn_f,     p_ds, 1 );
        SetDsL2EditRwEth2X(V, macSaRewriteEn_f,     p_ds, 1 );
    }

    if (p_sys_l2edit->vlan_profile_id)
    {
        SetDsL2EditRwEth2X(V, sVlanId_f,                p_ds, p_sys_l2edit->p_flex_edit->new_svid);
        SetDsL2EditRwEth2X(V, sCos_f,        p_ds,  p_sys_l2edit->p_flex_edit->new_scos);
        SetDsL2EditRwEth2X(V, cVlanId_f,                p_ds, p_sys_l2edit->p_flex_edit->new_cvid);
        SetDsL2EditRwEth2X(V, cCos_f,        p_ds,  p_sys_l2edit->p_flex_edit->new_ccos);
        SetDsL2EditRwEth2X(V, vlanActionProfileId_f,        p_ds,  p_sys_l2edit->vlan_profile_id);
    }

    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ETHERTYPE))
    {
        SetDsL2EditRwEth2X(V, etherTypeRewriteEn_f,     p_ds, 1 );
        SetDsL2EditRwEth2X(V, etherTypeValid_f,     p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACDA))
    {
        SetDsL2EditRwEth2X(V, macDaRewriteEn_f,     p_ds, 1 );
        SetDsL2EditRwEth2X(V, macDaValid_f,     p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_MACSA))
    {
        SetDsL2EditRwEth2X(V, macSaRewriteEn_f,     p_ds, 1 );
        SetDsL2EditRwEth2X(V, macSaValid_f,     p_ds, 1 );
    }
    SetDsL2EditRwEth2X(V, portDot1QValid_f,     p_ds, CTC_FLAG_ISSET(p_sys_l2edit->p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_FOLLOW_PORT_DOT1Q_TYPE));
    return CTC_E_NONE;

}


int32
sys_usw_nh_map_l2edit_gemport(uint8 lchip, sys_dsl2edit_eth_t* p_sys_l2edit, void *p_ds, uint32* p_offset)
{
    DsL2EditGemPort_m dsl2edit;
    uint32 gem_port_pass = 0;
    uint32 gem_vlan = 0;
    uint8 logic_port_low = 0;

    sal_memset(&dsl2edit, 0, sizeof(dsl2edit));
    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_L2EDIT_FLEX_8W,
                                                      p_sys_l2edit->offset, &dsl2edit));
    gem_port_pass = GetDsL2EditGemPort(V, pass_f,  &dsl2edit);
    gem_vlan = p_sys_l2edit->output_vid;
    logic_port_low = p_sys_l2edit->ether_type%8;
    SetDsL2EditGemPort(V, dsType_f,               &dsl2edit,  SYS_NH_DS_TYPE_L2EDIT);
    SetDsL2EditGemPort(V, l2EditType_f,         &dsl2edit,  DRV_ENUM(DRV_L2EDITTYPE_GEMPORT));
    DRV_SET_FIELD_VALUE(lchip, DsL2EditGemPort_t, DsL2EditGemPort_g_0_vlanId_f + logic_port_low, &dsl2edit, gem_vlan);
    CTC_BIT_SET(gem_port_pass, logic_port_low);
    SetDsL2EditGemPort(V, pass_f,       &dsl2edit,  gem_port_pass);
    sal_memcpy(p_ds , &dsl2edit, DRV_TABLE_ENTRY_SIZE(lchip, DsL2EditGemPort_t));
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_l3edit_addmpls(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    SetDsL3EditAddMpls1X(V, discardType_f,         p_ds,   p_sys_mpls->discard_type);
    SetDsL3EditAddMpls1X(V, discard_f,             p_ds,   p_sys_mpls->discard);
    SetDsL3EditAddMpls1X(V, dsType_f,              p_ds,   p_sys_mpls->ds_type);
    SetDsL3EditAddMpls1X(V, l3EditType_f,          p_ds,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditAddMpls1X(V, nextEditPtrValid_f,    p_ds,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditAddMpls1X(V, outerEditPtrType_f,    p_ds,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditAddMpls1X(V, outerEditPtr_f,        p_ds,   p_sys_mpls->outer_editptr);
    SetDsL3EditAddMpls1X(V, logicDestPortHigh_f,   p_ds,   p_sys_mpls->logic_dest_port);
    SetDsL3EditAddMpls1X(V, deriveLabel_f,         p_ds,   p_sys_mpls->derive_label);
    SetDsL3EditAddMpls1X(V, mplsOamIndex_f,        p_ds,   p_sys_mpls->mpls_oam_index);
    SetDsL3EditAddMpls1X(V, labelType_f,           p_ds,   p_sys_mpls->label_type);
    SetDsL3EditAddMpls1X(V, srcDscpType_f,         p_ds,   p_sys_mpls->src_dscp_type);
    SetDsL3EditAddMpls1X(V, mcastLabel_f,          p_ds,   p_sys_mpls->mcast_label);
    SetDsL3EditAddMpls1X(V, mapTtlMode_f,          p_ds,   p_sys_mpls->map_ttl_mode);
    SetDsL3EditAddMpls1X(V, mapTtl_f,              p_ds,   p_sys_mpls->map_ttl);
    SetDsL3EditAddMpls1X(V, statsPtr_f,            p_ds,   p_sys_mpls->statsptr);
    SetDsL3EditAddMpls1X(V, entropyLabelEn_f,      p_ds,   p_sys_mpls->entropy_label_en);
    SetDsL3EditAddMpls1X(V, permitMplsEvpnEsLabelEncaps_f,      p_ds,   p_sys_mpls->eslb_en);
    if (!p_sys_mpls->outer_editptr_type && (p_sys_mpls->outer_editptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditAddMpls1X(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditAddMpls1X(V, outerEditPtr_f,          p_ds,   (p_sys_mpls->outer_editptr-MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    if (p_sys_mpls->derive_exp)
    {
        if (p_sys_mpls->exp == 1)
        {
            /*mapping*/
            SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  p_ds,  2);
            SetDsL3EditAddMpls1X(V, uMplsPhb_gPtr_mplsTcPhbPtr_f,  p_ds, p_sys_mpls->mpls_domain);
        }
        else if (p_sys_mpls->exp == 0)
        {
            /*copy*/
            SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  p_ds,  3);
        }
    }
    else
    {
        SetDsL3EditAddMpls1X(V, uMplsPhb_gRaw_labelTc_f,  p_ds,   p_sys_mpls->exp);
        SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  p_ds,  1);
    }
    SetDsL3EditAddMpls1X(V, ttlIndex_f,            p_ds,   p_sys_mpls->ttl_index);
    SetDsL3EditAddMpls1X(V, label_f,               p_ds,   p_sys_mpls->label);
    SetDsL3EditAddMpls1X(V, editMode_f,               p_ds,   p_sys_mpls->edit_mode);

    return CTC_E_NONE;

}

int32
sys_usw_nh_unmap_l3edit_addmpls(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds)
{


    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_addmpls_spme(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    ds0_t dsmpls;
    ds0_t dsmpls_6w;

    sal_memset(&dsmpls_6w, 0, sizeof(dsmpls_6w));

    p_sys_mpls->offset = *p_offset;
    CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_L3EDIT_SPME,
                                                      p_sys_mpls->offset, &dsmpls_6w));


    sal_memset(&dsmpls, 0, sizeof(dsmpls));
    SetDsL3EditAddMpls1X(V, discardType_f,         &dsmpls,   p_sys_mpls->discard_type);
    SetDsL3EditAddMpls1X(V, discard_f,             &dsmpls,   p_sys_mpls->discard);
    SetDsL3EditAddMpls1X(V, dsType_f,              &dsmpls,   p_sys_mpls->ds_type);
    SetDsL3EditAddMpls1X(V, l3EditType_f,       &dsmpls,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditAddMpls1X(V, nextEditPtrValid_f,    &dsmpls,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditAddMpls1X(V, outerEditPtrType_f,    &dsmpls,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditAddMpls1X(V, outerEditPtr_f,        &dsmpls,   p_sys_mpls->outer_editptr);
    SetDsL3EditAddMpls1X(V, logicDestPortHigh_f,   &dsmpls,   p_sys_mpls->logic_dest_port);
    SetDsL3EditAddMpls1X(V, deriveLabel_f,         &dsmpls,   p_sys_mpls->derive_label);
    SetDsL3EditAddMpls1X(V, mplsOamIndex_f,        &dsmpls,   p_sys_mpls->mpls_oam_index);
    SetDsL3EditAddMpls1X(V, labelType_f,           &dsmpls,   p_sys_mpls->label_type);
    SetDsL3EditAddMpls1X(V, srcDscpType_f,         &dsmpls,   p_sys_mpls->src_dscp_type);
    SetDsL3EditAddMpls1X(V, mcastLabel_f,          &dsmpls,   p_sys_mpls->mcast_label);
    SetDsL3EditAddMpls1X(V, mapTtlMode_f,          &dsmpls,   p_sys_mpls->map_ttl_mode);
    SetDsL3EditAddMpls1X(V, mapTtl_f,              &dsmpls,   p_sys_mpls->map_ttl);
    SetDsL3EditAddMpls1X(V, statsPtr_f,            &dsmpls,   p_sys_mpls->statsptr);
    SetDsL3EditAddMpls1X(V, entropyLabelEn_f,      &dsmpls,   p_sys_mpls->entropy_label_en);

    if (p_sys_mpls->derive_exp)
    {
        /*Qos domain need retrieve, TBD*/
        if (p_sys_mpls->exp == 1)
        {
            /*mapping*/
            SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  &dsmpls,  2);
            SetDsL3EditAddMpls1X(V, uMplsPhb_gPtr_mplsTcPhbPtr_f,  &dsmpls, 0);
        }
        else if (p_sys_mpls->exp == 0)
        {
            /*copy*/
            SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  &dsmpls,  3);
        }
    }
    else
    {
        SetDsL3EditAddMpls1X(V, uMplsPhb_gRaw_labelTc_f,  &dsmpls,   p_sys_mpls->exp);
        SetDsL3EditAddMpls1X(V, mplsTcRemarkMode_f,  &dsmpls,  1);
    }
    SetDsL3EditAddMpls1X(V, ttlIndex_f,            &dsmpls,   p_sys_mpls->ttl_index);
    SetDsL3EditAddMpls1X(V, label_f,               &dsmpls,   p_sys_mpls->label);

    if (p_sys_mpls->offset % 2 == 0)
    {
        sal_memcpy((uint8*)&dsmpls_6w, &dsmpls, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditAddMpls1X_t));
    }
    else
    {
        sal_memcpy((uint8*)&dsmpls_6w + DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditAddMpls1X_t), &dsmpls, DRV_TABLE_ENTRY_SIZE(lchip, DsL3EditAddMpls1X_t));
    }

    sal_memcpy(p_ds , &dsmpls_6w, sizeof(dsmpls_6w));
    *p_offset = *p_offset / 2; /*dwfwd have two member*/

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_l3edit_addmpls_sr(uint8 lchip, sys_dsmpls_t* p_sys_mpls, void *p_ds, uint32* p_offset)
{
    uint8 i = 0;
    uint8 label_index = 0, step = 0;
    uint32 fld_base[]={DsL3EditAddMpls4X_s0_0_label_f, DsL3EditAddMpls4X_s0_0_tc_f, DsL3EditAddMpls4X_s0_0_ttl_f,
                       DsL3EditAddMpls4X_s1_0_label_f, DsL3EditAddMpls4X_s1_0_tc_f, DsL3EditAddMpls4X_s1_0_ttl_f};

    SetDsL3EditAddMpls4X(V, discardType_f,         p_ds,   p_sys_mpls->discard_type);
    SetDsL3EditAddMpls4X(V, discard_f,             p_ds,   p_sys_mpls->discard);
    SetDsL3EditAddMpls4X(V, dsType_f,              p_ds,   p_sys_mpls->ds_type);
    SetDsL3EditAddMpls4X(V, nextEditPtrValid_f,    p_ds,   p_sys_mpls->next_editptr_valid);
    SetDsL3EditAddMpls4X(V, outerEditPtrType_f,    p_ds,   p_sys_mpls->outer_editptr_type);
    SetDsL3EditAddMpls4X(V, outerEditPtr_f,        p_ds,   p_sys_mpls->outer_editptr);
    if (!p_sys_mpls->outer_editptr_type && (p_sys_mpls->outer_editptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditAddMpls4X(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditAddMpls4X(V, outerEditPtr_f,          p_ds,   (p_sys_mpls->outer_editptr-MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    for (i = 0; i < p_sys_mpls->label_num ; i++)
    {
        label_index = (i < 4) ? 0 : 3;
        step = (i < 4) ? i : (i - 4);
        DRV_SET_FIELD_V(lchip, DsL3EditAddMpls4X_t, fld_base[label_index] + step, p_ds,   p_sys_mpls->label_full[i] >> 12);
        if (0 == p_sys_mpls->derive_exp)
        {
            DRV_SET_FIELD_V(lchip, DsL3EditAddMpls4X_t, fld_base[label_index+1] + step, p_ds,   (p_sys_mpls->label_full[i] >> 9)&0x7);
        }
        else
        {
            DRV_SET_FIELD_V(lchip, DsL3EditAddMpls4X_t, fld_base[label_index+1] + step, p_ds,   ((p_sys_mpls->label_full[i] >> 9)&0x7) + (1 << 3) );
        }
        if (p_sys_mpls->map_ttl)
        {
             DRV_SET_FIELD_V(lchip, DsL3EditAddMpls4X_t, fld_base[label_index+2] + step, p_ds,   (p_sys_mpls->ttl_index &0xFF) + (1 << 8));
        }
        else
        {
            DRV_SET_FIELD_V(lchip, DsL3EditAddMpls4X_t, fld_base[label_index+2] + step, p_ds,   (p_sys_mpls->label_full[i] &0xFF));
        }
    }
    SetDsL3EditAddMpls4X(V, l3EditType_f,          p_ds,   p_sys_mpls->l3_rewrite_type);
    SetDsL3EditAddMpls4X(V, labelNum_f,            p_ds,   p_sys_mpls->label_num - 1);
    SetDsL3EditAddMpls4X(V, labelNumHigh_f,        p_ds,   (p_sys_mpls->label_num - 1)>>2);
    SetDsL3EditAddMpls4X(V, mapTtlMode_f,          p_ds,   p_sys_mpls->map_ttl_mode);

    if (p_sys_mpls->derive_exp)
    {
        if (p_sys_mpls->exp == 1)/*mapping*/
        {
            SetDsL3EditAddMpls4X(V, mplsTcRemarkMode_f,  p_ds,  2);
        }
        else if (p_sys_mpls->exp == 0)/*copy*/
        {
            SetDsL3EditAddMpls4X(V, mplsTcRemarkMode_f,  p_ds,  3);
        }
    }
    else
    {
        SetDsL3EditAddMpls4X(V, mplsTcRemarkMode_f,  p_ds,  1);
    }
    SetDsL3EditAddMpls4X(V, statsPtr_f,          p_ds,   p_sys_mpls->statsptr);

    return CTC_E_NONE;

}


int32
sys_usw_nh_map_l3edit_addip4(uint8 lchip, sys_dsl3edit_tunnelv4_t* p_sys_tunnel, void *p_ds, uint32* p_offset)
{
    if (0 == p_sys_tunnel->inner_header_type)
    {
        SetDsL3EditAddIp4(V, autoIpProtocolTypeMode_f, p_ds,   p_sys_tunnel->ip_protocol_type? 0 : 1);
    }
    SetDsL3EditAddIp4(V, udpSrcPortUseHash_f,            p_ds,   0);
    SetDsL3EditAddIp4(V, ecnCopyMode_f,           p_ds,   p_sys_tunnel->ecn_mode);
    SetDsL3EditAddIp4(V, discardType_f,           p_ds,   0);
    SetDsL3EditAddIp4(V, discard_f,               p_ds,   0);
    SetDsL3EditAddIp4(V, dsType_f,                p_ds,   p_sys_tunnel->ds_type);
    SetDsL3EditAddIp4(V, l3EditType_f,         p_ds,   p_sys_tunnel->l3_rewrite_type);
    SetDsL3EditAddIp4(V, nextEditPtrValid_f,      p_ds,   p_sys_tunnel->out_l2edit_valid);
    SetDsL3EditAddIp4(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditAddIp4(V, outerEditPtr_f,          p_ds,   p_sys_tunnel->out_l2edit_valid ? (p_sys_tunnel->l2edit_ptr) : 0);
    SetDsL3EditAddIp4(V, ipSaValid_f,             p_ds,   p_sys_tunnel->ipsa_valid);
    SetDsL3EditAddIp4(V, mtuSize_f,               p_ds,   p_sys_tunnel->mtu_size);
    SetDsL3EditAddIp4(V, mapTtl_f,                p_ds,   p_sys_tunnel->map_ttl);
    SetDsL3EditAddIp4(V, isatpTunnel_f,     p_ds,   p_sys_tunnel->isatp_tunnel);
    SetDsL3EditAddIp4(V, copyDontFrag_f,          p_ds,   p_sys_tunnel->copy_dont_frag);
    SetDsL3EditAddIp4(V, dontFrag_f,              p_ds,   p_sys_tunnel->dont_frag);
    SetDsL3EditAddIp4(V, ttl_f,                   p_ds,   p_sys_tunnel->ttl);
    SetDsL3EditAddIp4(V, tunnel6To4Sa_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa);
    SetDsL3EditAddIp4(V, tunnel6To4Da_f,    p_ds,   p_sys_tunnel->tunnel6_to4_da);
    SetDsL3EditAddIp4(V, mtuCheckEn_f,            p_ds,   p_sys_tunnel->mtu_check_en);
    SetDsL3EditAddIp4(V, l4EditType_f,    p_ds,   p_sys_tunnel->inner_header_type);
    SetDsL3EditAddIp4(V, ipDa_f,                  p_ds,   p_sys_tunnel->ipda);
    SetDsL3EditAddIp4(V, ipSaIndex_f,             p_ds,   p_sys_tunnel->ipsa_index);
    SetDsL3EditAddIp4(V, statsPtr_f,              p_ds,   p_sys_tunnel->stats_ptr);
    SetDsL3EditAddIp4(V, ipIdentificationType_f,           p_ds,   0);
    SetDsL3EditAddIp4(V, packetLengthType_f,           p_ds,   1);
    SetDsL3EditAddIp4(V, dscpRemarkMode_f,        p_ds,   p_sys_tunnel->derive_dscp);
    SetDsL3EditAddIp4(V, xEditPtr_f,              p_ds,   p_sys_tunnel->xedit_ptr);/*AT*/
    if (p_sys_tunnel->out_l2edit_valid && (p_sys_tunnel->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditAddIp4(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditAddIp4(V, outerEditPtr_f,          p_ds,   (p_sys_tunnel->l2edit_ptr - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }

    if (p_sys_tunnel->derive_dscp == 1)
    {
        /*assign*/
        SetDsL3EditAddIp4(V, uDscpPhb_gRaw_dscp_f,    p_ds,   p_sys_tunnel->dscp);
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        /*map*/
        SetDsL3EditAddIp4(V, uDscpPhb_gPtr_dscpPhbPtr_f,     p_ds,   p_sys_tunnel->dscp_domain);
    }
    if (p_sys_tunnel->int_en)
    {
        SetDsL3EditAddIp4(V, intHdrEn_f,            p_ds,   p_sys_tunnel->int_en);
    }

    SetDsL3EditAddIp44X(V, spanExtendHeaderValid_f,             p_ds,   p_sys_tunnel->xerspan_hdr_en);
    if (p_sys_tunnel->cloud_sec_en)
    {
        SetDsL3EditAddIp44X(V, cloudSecEn_f,             p_ds,   1);
        SetDsL3EditAddIp44X(V, transmitScId_f,     p_ds,   p_sys_tunnel->sc_index);
    }
    if (p_sys_tunnel->udf_profile_id)
    {
        SetDsL3EditAddIp44X(V, flexTunnelEnable_f,           p_ds,   1);
        SetDsL3EditAddIp44X(V, flexHdrIndex_f,           p_ds,   p_sys_tunnel->udf_profile_id-1);

        if(p_sys_tunnel->udf_edit[3] || p_sys_tunnel->udf_edit[2])
        {
            if(!p_sys_tunnel->is_12w)
            {
                SetDsL3EditAddIp4(V, statsPtr_f,     p_ds,   p_sys_tunnel->udf_edit[2]);
                SetDsL3EditAddIp4(V, mtuSize_f,     p_ds,   p_sys_tunnel->udf_edit[3] & 0x3FFF);
                SetDsL3EditAddIp4(V, flexTunnelDataHigh_f,     p_ds,   p_sys_tunnel->udf_edit[3] >> 14);
                SetDsL3EditAddIp4(V, flexTunnelDataShareMode_f,     p_ds,   1);
            }
            else if (DRV_FROM_AT(lchip))
            {
                SetDsL3EditAddIp44X(V, flexEditTunnelData_f,      p_ds,   (p_sys_tunnel->udf_edit[3] << 16) + p_sys_tunnel->udf_edit[2] );
            }
            else
            {
                SetDsL3EditAddIp44X(V, vxlanFamilyId_f,           p_ds,   p_sys_tunnel->udf_profile_id - 1);
                SetDsL3EditAddIp44X(V, statsPtr_f,           p_ds,   p_sys_tunnel->udf_edit[2]);
                SetDsL3EditAddIp44X(V, mtuSize_f,           p_ds,   p_sys_tunnel->udf_edit[3]);
                SetDsL3EditAddIp44X(V, udpSrcPortUseDest_f,      p_ds,   (p_sys_tunnel->udf_edit[3] >> 14) );
                SetDsL3EditAddIp44X(V, udpSrcPortUseHash_f,      p_ds,   (p_sys_tunnel->udf_edit[3] >> 15) );
                SetDsL3EditAddIp44X(V, intHdrEn_f,      p_ds,   1 );
            }
        }
    }

    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_GRE:
        SetDsL3EditAddIp4(V, greProtocol_f,     p_ds,   p_sys_tunnel->gre_protocol);
        SetDsL3EditAddIp4(V, greVersion_f,      p_ds,   p_sys_tunnel->gre_version);
        SetDsL3EditAddIp4(V, greAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_gre_auto);
        SetDsL3EditAddIp4(V, greFlagK_f,        p_ds,   p_sys_tunnel->gre_flags >> 1);
        SetDsL3EditAddIp44X(V, greKey_f,      p_ds,   p_sys_tunnel->gre_key);/*12W*/
        SetDsL3EditAddIp44X(V, greKeyValid_f,      p_ds,   (p_sys_tunnel->gre_key)?1:0);/*12W*/
        SetDsL3EditAddIp4(V, ipSa_f,         p_ds,   p_sys_tunnel->ipsa);
        SetDsL3EditAddIp4(V, ipSaValid_f,            p_ds,   1);
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6RD:
        SetDsL3EditAddIp4(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        SetDsL3EditAddIp4(V, tunnel6To4Ipv6PrefixLength_f,      p_ds,   p_sys_tunnel->tunnel6_to4_da_ipv6_prefixlen);
        SetDsL3EditAddIp4(V, tunnel6To4Ipv4PrefixLength_f,      p_ds,   p_sys_tunnel->tunnel6_to4_da_ipv4_prefixlen);
        SetDsL3EditAddIp4(V, tunnel6To4SaIpv6PrefixLength_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa_ipv6_prefixlen);
        SetDsL3EditAddIp4(V, tunnel6To4SaIpv4PrefixLength_f,    p_ds,   p_sys_tunnel->tunnel6_to4_sa_ipv4_prefixlen);
        if (p_sys_tunnel->tunnel6_to4_sa)
        {
            SetDsL3EditAddIp4(V, ipSa_f,     p_ds,   (p_sys_tunnel->ipsa_6to4));
            SetDsL3EditAddIp4(V, tunnel6To4Sa_f,     p_ds,   1);
        }
        else
        {
            SetDsL3EditAddIp4(V, ipSa_f,         p_ds,   p_sys_tunnel->ipsa);
            SetDsL3EditAddIp4(V, ipSaValid_f,            p_ds,   1);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6TO4:
        SetDsL3EditAddIp4(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        if (!p_sys_tunnel->tunnel6_to4_sa)
        {
            SetDsL3EditAddIp4(V, ipSa_f,         p_ds,   p_sys_tunnel->ipsa);
            SetDsL3EditAddIp4(V, ipSaValid_f,            p_ds,   1);
        }
        if (p_sys_tunnel->l4_dest_port && p_sys_tunnel->l4_src_port)
        {
            SetDsL3EditAddIp4(V, udpDestPort_f,     p_ds,   p_sys_tunnel->l4_dest_port);
            SetDsL3EditAddIp4(V, udpSrcPort_f,      p_ds,   p_sys_tunnel->l4_src_port);
            SetDsL3EditAddIp4(V, udpSrcPortValid_f,      p_ds,   1);
            SetDsL3EditAddIp4(V, ipSaValid_f,             p_ds,   p_sys_tunnel->ipsa_valid);
            SetDsL3EditAddIp4(V, ipSa_f,             p_ds,   p_sys_tunnel->ipsa);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_NVGRE:
        SetDsL3EditAddIp4(V, greAutoIdentifyProtocol_f,   p_ds,   1);
        SetDsL3EditAddIp4(V, greFlagK_f,        p_ds,   p_sys_tunnel->gre_flags >> 1);
        SetDsL3EditAddIp4(V, ipSa_f,         p_ds,   p_sys_tunnel->ipsa);
        SetDsL3EditAddIp4(V, ipSaValid_f,            p_ds,   1);
        SetDsL3EditAddIp44X(V, greKeyValid_f,      p_ds,   0);/*12W*/
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_VXLAN:
        SetDsL3EditAddIp4(V, udpTunnelType_f,   p_ds,   1);
        SetDsL3EditAddIp4(V, udpDestPort_f,   p_ds,   p_sys_tunnel->l4_dest_port);
        SetDsL3EditAddIp4(V, udpSrcPortUseHash_f,            p_ds,   !p_sys_tunnel->udp_src_port_en);
        SetDsL3EditAddIp4(V, udpSrcPortValid_f,   p_ds,   p_sys_tunnel->udp_src_port_en);
        SetDsL3EditAddIp4(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        SetDsL3EditAddIp4(V, ipSa_f,         p_ds,   p_sys_tunnel->ipsa);
        SetDsL3EditAddIp4(V, ipSaValid_f,            p_ds,   1);
        SetDsL3EditAddIp4(V, vxlanFamilyId_f,            p_ds,   p_sys_tunnel->vxlan_edit_idx);
        break;
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_NAT64:
        SetDsL3EditAddIp4(V, u_rw_replaceTcpPort_f,           p_ds,   1);
        SetDsL3EditAddIp4(V, u_rw_replaceUdpPort_f,           p_ds,   1);
        SetDsL3EditAddIp4(V, u_rw_l4DstPortReplaceMode_f,        p_ds,   SYS_L3EDITRW_MODE_DEST);
        SetDsL3EditAddIp4(V, u_rw_l4SrcPortReplaceMode_f,              p_ds,   SYS_L3EDITRW_MODE_SRC);
        break;
    default:
        break;
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_addip4(uint8 lchip, sys_dsl3edit_tunnelv4_t* p_sys_tunnel, void *p_ds)
{
    uint8 is_12w = 0;
    p_sys_tunnel->ecn_mode = GetDsL3EditAddIp4(V, ecnCopyMode_f, p_ds);
    p_sys_tunnel->ds_type = GetDsL3EditAddIp4(V, dsType_f, p_ds);
    p_sys_tunnel->l3_rewrite_type = GetDsL3EditAddIp4(V, l3EditType_f, p_ds);
    if(DRV_ENUM(DRV_L3EDITTYPE_ADDIP44X) == p_sys_tunnel->l3_rewrite_type)
    {
        is_12w = 1;
    }
    p_sys_tunnel->out_l2edit_valid = GetDsL3EditAddIp4(V, nextEditPtrValid_f, p_ds);
    p_sys_tunnel->l2edit_ptr = GetDsL3EditAddIp4(V, outerEditPtr_f, p_ds);
    p_sys_tunnel->ipsa_valid = GetDsL3EditAddIp4(V, ipSaValid_f, p_ds);
    p_sys_tunnel->mtu_size = GetDsL3EditAddIp4(V, mtuSize_f, p_ds);
    p_sys_tunnel->map_ttl = GetDsL3EditAddIp4(V, mapTtl_f, p_ds);
    p_sys_tunnel->isatp_tunnel = GetDsL3EditAddIp4(V, isatpTunnel_f, p_ds);
    p_sys_tunnel->copy_dont_frag = GetDsL3EditAddIp4(V, copyDontFrag_f, p_ds);
    p_sys_tunnel->dont_frag = GetDsL3EditAddIp4(V, dontFrag_f, p_ds);
    p_sys_tunnel->ttl = GetDsL3EditAddIp4(V, ttl_f, p_ds);
    p_sys_tunnel->tunnel6_to4_sa = GetDsL3EditAddIp4(V, tunnel6To4Sa_f, p_ds);
    p_sys_tunnel->tunnel6_to4_da = GetDsL3EditAddIp4(V, tunnel6To4Da_f, p_ds);
    p_sys_tunnel->mtu_check_en = GetDsL3EditAddIp4(V, mtuCheckEn_f, p_ds);
    p_sys_tunnel->inner_header_type = GetDsL3EditAddIp4(V, l4EditType_f, p_ds);
    p_sys_tunnel->ipda = GetDsL3EditAddIp4(V, ipDa_f, p_ds);
    p_sys_tunnel->ipsa_index = GetDsL3EditAddIp4(V, ipSaIndex_f, p_ds);
    p_sys_tunnel->stats_ptr = GetDsL3EditAddIp4(V, statsPtr_f, p_ds);
    p_sys_tunnel->derive_dscp = GetDsL3EditAddIp4(V, dscpRemarkMode_f, p_ds);
    p_sys_tunnel->xedit_ptr = GetDsL3EditAddIp4(V, xEditPtr_f, p_ds);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        p_sys_tunnel->dscp = GetDsL3EditAddIp4(V, uDscpPhb_gRaw_dscp_f, p_ds);
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        p_sys_tunnel->dscp_domain = GetDsL3EditAddIp4(V, uDscpPhb_gPtr_dscpPhbPtr_f, p_ds);
    }
    p_sys_tunnel->int_en = GetDsL3EditAddIp4(V, intHdrEn_f, p_ds);

    if (is_12w)
    {
        if (GetDsL3EditAddIp44X(V, cloudSecEn_f, p_ds))
        {
            p_sys_tunnel->cloud_sec_en = 1;
            p_sys_tunnel->sc_index = GetDsL3EditAddIp44X(V, transmitScId_f, p_ds);
        }
        p_sys_tunnel->xerspan_hdr_en = GetDsL3EditAddIp44X(V, spanExtendHeaderValid_f, p_ds);
        if (GetDsL3EditAddIp44X(V, flexTunnelEnable_f, p_ds))
        {
            p_sys_tunnel->udf_profile_id = GetDsL3EditAddIp44X(V, flexHdrIndex_f, p_ds) + 1;
        }
    }

    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_GRE:
        p_sys_tunnel->gre_protocol = GetDsL3EditAddIp4(V, greProtocol_f, p_ds);
        p_sys_tunnel->gre_version = GetDsL3EditAddIp4(V, greVersion_f, p_ds);
        p_sys_tunnel->is_gre_auto = GetDsL3EditAddIp4(V, greAutoIdentifyProtocol_f, p_ds);
        p_sys_tunnel->gre_flags = GetDsL3EditAddIp4(V, greFlagK_f, p_ds) << 1;
        p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        if (is_12w)
        {
            if (GetDsL3EditAddIp44X(V, greKeyValid_f, p_ds))
            {
                p_sys_tunnel->gre_key = GetDsL3EditAddIp44X(V, greKey_f, p_ds);/*12W*/
            }
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6RD:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditAddIp4(V, ipProtocolType_f, p_ds);
        p_sys_tunnel->tunnel6_to4_da_ipv6_prefixlen = GetDsL3EditAddIp4(V, tunnel6To4Ipv6PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_da_ipv4_prefixlen = GetDsL3EditAddIp4(V, tunnel6To4Ipv4PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_sa_ipv6_prefixlen = GetDsL3EditAddIp4(V, tunnel6To4SaIpv6PrefixLength_f, p_ds);
        p_sys_tunnel->tunnel6_to4_sa_ipv4_prefixlen = GetDsL3EditAddIp4(V, tunnel6To4SaIpv4PrefixLength_f, p_ds);
        if (GetDsL3EditAddIp4(V, tunnel6To4Sa_f, p_ds))
        {
            p_sys_tunnel->tunnel6_to4_sa = 1;
            p_sys_tunnel->ipsa_6to4 = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        }
        if(GetDsL3EditAddIp4(V, ipSaValid_f, p_ds))
        {
            p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_6TO4:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditAddIp4(V, ipProtocolType_f, p_ds);
        if(GetDsL3EditAddIp4(V, ipSaValid_f, p_ds))
        {
            p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        }
        if (GetDsL3EditAddIp4(V, udpSrcPortValid_f, p_ds))
        {
            p_sys_tunnel->l4_dest_port = GetDsL3EditAddIp4(V, udpDestPort_f, p_ds);
            p_sys_tunnel->l4_src_port = GetDsL3EditAddIp4(V, udpSrcPort_f, p_ds);
            p_sys_tunnel->ipsa_valid = GetDsL3EditAddIp4(V, ipSaValid_f, p_ds);
            p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_NVGRE:
        p_sys_tunnel->gre_flags = GetDsL3EditAddIp4(V, greFlagK_f, p_ds) << 1;
        p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f,         p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV4_SHARE_TYPE_VXLAN:
        p_sys_tunnel->l4_dest_port = GetDsL3EditAddIp4(V, udpDestPort_f, p_ds);
        p_sys_tunnel->udp_src_port_en = GetDsL3EditAddIp4(V, udpSrcPortValid_f, p_ds);
        if (p_sys_tunnel->udp_src_port_en)
        {
            p_sys_tunnel->l4_src_port = GetDsL3EditAddIp4(V, udpSrcPort_f, p_ds);
        }
        if(GetDsL3EditAddIp4(V, ipSaValid_f, p_ds))
        {
            p_sys_tunnel->ipsa = GetDsL3EditAddIp4(V, ipSa_f, p_ds);
        }
        p_sys_tunnel->vxlan_edit_idx = GetDsL3EditAddIp4(V, vxlanFamilyId_f, p_ds);
        break;
    default:
        break;
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_addip6(uint8 lchip, sys_dsl3edit_tunnelv6_t* p_sys_tunnel, void *p_ds, uint32* p_offset)
{
    if (0 == p_sys_tunnel->inner_header_type)
    {
        SetDsL3EditAddIp6(V, autoIpProtocolTypeMode_f, p_ds,   p_sys_tunnel->auto_protocol? 1 : (p_sys_tunnel->ip_protocol_type? 0 : 1));
    }
    SetDsL3EditAddIp6(V, udpSrcPortUseHash_f,            p_ds,   0);
    SetDsL3EditAddIp6(V, ecnCopyMode_f,           p_ds,   p_sys_tunnel->ecn_mode);
    SetDsL3EditAddIp6(V, discardType_f,           p_ds,   0);
    SetDsL3EditAddIp6(V, discard_f,               p_ds,   0);
    SetDsL3EditAddIp6(V, dsType_f,                p_ds,   p_sys_tunnel->ds_type);
    SetDsL3EditAddIp6(V, l3EditType_f,            p_ds,   p_sys_tunnel->l3_rewrite_type);
    SetDsL3EditAddIp6(V, nextEditPtrValid_f,      p_ds,   p_sys_tunnel->out_l2edit_valid);
    SetDsL3EditAddIp6(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditAddIp6(V, outerEditPtr_f,          p_ds,   p_sys_tunnel->out_l2edit_valid ? (p_sys_tunnel->l2edit_ptr) : 0);
    SetDsL3EditAddIp6(V, mtuCheckEn_f,            p_ds,   p_sys_tunnel->mtu_check_en);
    SetDsL3EditAddIp6(V, mtuSize_f,               p_ds,   p_sys_tunnel->mtu_size);
    SetDsL3EditAddIp6(V, mapTtl_f,                p_ds,   p_sys_tunnel->map_ttl);
    SetDsL3EditAddIp6(V, newFlowLabelMode_f,      p_ds,   p_sys_tunnel->new_flow_label_mode);
    SetDsL3EditAddIp6(V, ttl_f,                   p_ds,   p_sys_tunnel->ttl);
    SetDsL3EditAddIp6(V, l4EditType_f,    p_ds,   p_sys_tunnel->inner_header_type);
    SetDsL3EditAddIp6(V, flowLabel_f,             p_ds,   p_sys_tunnel->flow_label);
    SetDsL3EditAddIp6(V, newFlowLabelValid_f,     p_ds,   p_sys_tunnel->new_flow_label_valid);
    SetDsL3EditAddIp6(V, ipSaIndex_f,             p_ds,   p_sys_tunnel->ipsa_index);
    SetDsL3EditAddIp6(A, ipDa_f,                  p_ds,   p_sys_tunnel->ipda);
    SetDsL3EditAddIp6(V, statsPtr_f,              p_ds,   p_sys_tunnel->stats_ptr);
    SetDsL3EditAddIp6(V, spanExtendHeaderValid_f, p_ds,   p_sys_tunnel->xerspan_hdr_en);
    SetDsL3EditAddIp6(V, packetLengthType_f,      p_ds,   1);
    SetDsL3EditAddIp6(V, xEditPtr_f,              p_ds,   p_sys_tunnel->xedit_ptr);/*AT*/
    if (p_sys_tunnel->int_en)
    {
        SetDsL3EditAddIp6(V, intHdrEn_f,            p_ds,   p_sys_tunnel->int_en);
    }

    if (p_sys_tunnel->out_l2edit_valid && (p_sys_tunnel->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditAddIp6(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditAddIp6(V, outerEditPtr_f,          p_ds,   (p_sys_tunnel->l2edit_ptr - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    if (p_sys_tunnel->cloud_sec_en)
    {
        SetDsL3EditAddIp6(V, cloudSecEn_f,             p_ds,   1);
        SetDsL3EditAddIp6(V, transmitScId_f,     p_ds,   p_sys_tunnel->sc_index);
    }

    if (p_sys_tunnel->udf_profile_id)
    {
        SetDsL3EditAddIp6(V, flexTunnelEnable_f,           p_ds,   1);
        SetDsL3EditAddIp6(V, flexHdrIndex_f,           p_ds,   ((p_sys_tunnel->udf_profile_id-1)&0x7));
        if(p_sys_tunnel->udf_edit[3] || p_sys_tunnel->udf_edit[2])
        {
            if (DRV_FROM_AT(lchip))
            {
                SetDsL3EditAddIp6(V, flexEditTunnelData_f,      p_ds,   (p_sys_tunnel->udf_edit[3] << 16) + p_sys_tunnel->udf_edit[2] );
            }
            else
            {
                SetDsL3EditAddIp6(V, vxlanFamilyId_f,           p_ds,   p_sys_tunnel->udf_profile_id - 1);
                SetDsL3EditAddIp6(V, statsPtr_f,           p_ds,   p_sys_tunnel->udf_edit[2]);
                SetDsL3EditAddIp6(V, mtuSize_f,           p_ds,   p_sys_tunnel->udf_edit[3]);
                SetDsL3EditAddIp6(V, udpSrcPortUseDest_f,      p_ds,   (p_sys_tunnel->udf_edit[3] >> 14) );
                SetDsL3EditAddIp6(V, udpSrcPortUseHash_f,      p_ds,   (p_sys_tunnel->udf_edit[3] >> 15) );
                SetDsL3EditAddIp6(V, intHdrEn_f,      p_ds,   1 );
            }
        }
    }

    SetDsL3EditAddIp6(V, dscpRemarkMode_f,        p_ds,   p_sys_tunnel->derive_dscp);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        /*assign*/
        SetDsL3EditAddIp6(V, uDscpPhb_gRaw_dscp_f,    p_ds,   (p_sys_tunnel->tos>>2));
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        /*map*/
        SetDsL3EditAddIp6(V, uDscpPhb_gPtr_dscpPhbPtr_f,     p_ds,   p_sys_tunnel->dscp_domain);
    }
    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_GRE:
        SetDsL3EditAddIp6(V, greProtocol_f,     p_ds,   p_sys_tunnel->gre_protocol);
        SetDsL3EditAddIp6(V, greVersion_f,      p_ds,   p_sys_tunnel->gre_version);
        SetDsL3EditAddIp6(V, greAutoIdentifyProtocol_f, p_ds,   p_sys_tunnel->is_gre_auto);
        SetDsL3EditAddIp6(V, greFlagK_f,        p_ds,   p_sys_tunnel->gre_flags >> 1);
        SetDsL3EditAddIp6(V, greKey_f,      p_ds,   p_sys_tunnel->gre_key);/*12W*/
        SetDsL3EditAddIp6(V, greKeyValid_f,      p_ds,   (p_sys_tunnel->gre_key)?1:0);/*12W*/
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NORMAL:
        if (p_sys_tunnel->l4_dest_port && p_sys_tunnel->l4_src_port)
        {
            SetDsL3EditAddIp6(V, udpDestPort_f, p_ds, p_sys_tunnel->l4_dest_port);
            SetDsL3EditAddIp6(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        }
        else
        {
            SetDsL3EditAddIp6(V, ipProtocolType_f,  p_ds,   p_sys_tunnel->ip_protocol_type);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NVGRE:
        SetDsL3EditAddIp6(V, greAutoIdentifyProtocol_f,  p_ds,  1);
        SetDsL3EditAddIp6(V, greFlagK_f,        p_ds,   p_sys_tunnel->gre_flags >> 1);
        SetDsL3EditAddIp6(V, greKeyValid_f,      p_ds,  0);/*12W*/
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_VXLAN:
        SetDsL3EditAddIp6(V, udpTunnelType_f,   p_ds,   3);
        SetDsL3EditAddIp6(V, udpDestPort_f,   p_ds,   p_sys_tunnel->l4_dest_port);
        SetDsL3EditAddIp6(V, udpSrcPortUseHash_f,            p_ds,   !p_sys_tunnel->udp_src_port_en);
        SetDsL3EditAddIp6(V, udpSrcPort_f, p_ds, p_sys_tunnel->l4_src_port);
        SetDsL3EditAddIp6(V, vxlanFamilyId_f,            p_ds,   p_sys_tunnel->vxlan_edit_idx);
        break;
    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NAT46:
        SetDsL3EditAddIp6(V, u_rw_data_replaceTcpPort_f,           p_ds,   1);
        SetDsL3EditAddIp6(V, u_rw_data_replaceUdpPort_f,           p_ds,   1);
        SetDsL3EditAddIp6(V, u_rw_data_l4DstPortReplaceMode_f,        p_ds,   SYS_L3EDITRW_MODE_DEST);
        SetDsL3EditAddIp6(V, u_rw_data_l4SrcPortReplaceMode_f,              p_ds,   SYS_L3EDITRW_MODE_SRC);
    default:
        break;
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_addip6(uint8 lchip, sys_dsl3edit_tunnelv6_t* p_sys_tunnel, void *p_ds)
{
    p_sys_tunnel->ecn_mode = GetDsL3EditAddIp6(V, ecnCopyMode_f, p_ds);
    p_sys_tunnel->ds_type = GetDsL3EditAddIp6(V, dsType_f, p_ds);
    p_sys_tunnel->l3_rewrite_type = GetDsL3EditAddIp6(V, l3EditType_f, p_ds);
    p_sys_tunnel->out_l2edit_valid = GetDsL3EditAddIp6(V, nextEditPtrValid_f, p_ds);
    p_sys_tunnel->l2edit_ptr = GetDsL3EditAddIp6(V, outerEditPtr_f, p_ds);
    p_sys_tunnel->mtu_check_en = GetDsL3EditAddIp6(V, mtuCheckEn_f, p_ds);
    p_sys_tunnel->mtu_size = GetDsL3EditAddIp6(V, mtuSize_f, p_ds);
    p_sys_tunnel->map_ttl = GetDsL3EditAddIp6(V, mapTtl_f, p_ds);
    p_sys_tunnel->new_flow_label_mode = GetDsL3EditAddIp6(V, newFlowLabelMode_f, p_ds);
    p_sys_tunnel->ttl = GetDsL3EditAddIp6(V, ttl_f, p_ds);
    p_sys_tunnel->inner_header_type = GetDsL3EditAddIp6(V, l4EditType_f, p_ds);
    p_sys_tunnel->flow_label = GetDsL3EditAddIp6(V, flowLabel_f, p_ds);
    p_sys_tunnel->new_flow_label_valid = GetDsL3EditAddIp6(V, newFlowLabelValid_f, p_ds);
    p_sys_tunnel->ipsa_index = GetDsL3EditAddIp6(V, ipSaIndex_f, p_ds);
    GetDsL3EditAddIp6(A, ipDa_f, p_ds,   p_sys_tunnel->ipda);
    p_sys_tunnel->stats_ptr = GetDsL3EditAddIp6(V, statsPtr_f, p_ds);
    p_sys_tunnel->xerspan_hdr_en = GetDsL3EditAddIp6(V, spanExtendHeaderValid_f, p_ds);
    p_sys_tunnel->xedit_ptr = GetDsL3EditAddIp6(V, xEditPtr_f, p_ds);
    if (GetDsL3EditAddIp6(V, cloudSecEn_f, p_ds))
    {
        p_sys_tunnel->cloud_sec_en = 1;
        p_sys_tunnel->sc_index = GetDsL3EditAddIp6(V, transmitScId_f, p_ds);
    }
    if (GetDsL3EditAddIp6(V, flexTunnelEnable_f, p_ds))
    {
        p_sys_tunnel->udf_profile_id = 1;
        p_sys_tunnel->udf_profile_id = GetDsL3EditAddIp6(V, flexHdrIndex_f, p_ds) +  1;
    }
    p_sys_tunnel->derive_dscp = GetDsL3EditAddIp6(V, dscpRemarkMode_f, p_ds);
    if (p_sys_tunnel->derive_dscp == 1)
    {
        p_sys_tunnel->tos = GetDsL3EditAddIp6(V, uDscpPhb_gRaw_dscp_f, p_ds) << 2;
    }
    else if (p_sys_tunnel->derive_dscp == 2)
    {
        p_sys_tunnel->dscp_domain = GetDsL3EditAddIp6(V, uDscpPhb_gPtr_dscpPhbPtr_f, p_ds);
    }
    p_sys_tunnel->int_en = GetDsL3EditAddIp6(V, intHdrEn_f, p_ds);
    switch(p_sys_tunnel->share_type)
    {
    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_GRE:
        p_sys_tunnel->gre_protocol = GetDsL3EditAddIp6(V, greProtocol_f, p_ds);
        p_sys_tunnel->gre_version = GetDsL3EditAddIp6(V, greVersion_f, p_ds);
        p_sys_tunnel->is_gre_auto = GetDsL3EditAddIp6(V, greAutoIdentifyProtocol_f, p_ds);
        p_sys_tunnel->gre_flags = GetDsL3EditAddIp6(V, greFlagK_f, p_ds) << 1;
        if (GetDsL3EditAddIp6(V, greKeyValid_f, p_ds))
        {
            p_sys_tunnel->gre_key = GetDsL3EditAddIp6(V, greKey_f, p_ds);
        }
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NORMAL:
        p_sys_tunnel->ip_protocol_type = GetDsL3EditAddIp6(V, ipProtocolType_f, p_ds);
        p_sys_tunnel->l4_dest_port = GetDsL3EditAddIp6(V, udpDestPort_f, p_ds);
        p_sys_tunnel->l4_src_port = GetDsL3EditAddIp6(V, udpSrcPort_f, p_ds);
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_NVGRE:
        p_sys_tunnel->gre_flags = GetDsL3EditAddIp6(V, greFlagK_f, p_ds) << 1;
        break;

    case SYS_NH_L3EDIT_TUNNELV6_SHARE_TYPE_VXLAN:
        p_sys_tunnel->l4_dest_port = GetDsL3EditAddIp6(V, udpDestPort_f, p_ds);
        p_sys_tunnel->udp_src_port_en = !GetDsL3EditAddIp6(V, udpSrcPortUseHash_f, p_ds);
        p_sys_tunnel->l4_src_port = GetDsL3EditAddIp6(V, udpSrcPort_f, p_ds);
        p_sys_tunnel->vxlan_edit_idx = GetDsL3EditAddIp6(V, vxlanFamilyId_f, p_ds);
        break;
    default:
        break;
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_rwip4(uint8 lchip, ctc_misc_nh_flex_edit_param_t* p_flex_edit, void *p_ds, uint32* p_offset)
{
    uint8 flex_tos = 0;
    SetDsL3EditRwIp4(V, discard_f ,          p_ds, 0);
    SetDsL3EditRwIp4(V, discardType_f ,      p_ds, 0);
    SetDsL3EditRwIp4(V, nextEditPtrValid_f , p_ds, 0);
    SetDsL3EditRwIp4(V, outerEditPtr_f ,     p_ds, 0);
    SetDsL3EditRwIp4(V, outerEditPtrType_f , p_ds, 0);
    SetDsL3EditRwIp4(V, statsPtr_f ,         p_ds, 0);
    SetDsL3EditRwIp4(V, dsType_f,            p_ds, SYS_NH_DS_TYPE_L3EDIT);
    SetDsL3EditRwIp4(V, l3EditType_f,     p_ds, DRV_ENUM(DRV_L3EDITTYPE_RWIP4));

    SetDsL3EditRwIp4(V, ipAddr0_f,     p_ds, p_flex_edit->ip_da.ipv4);
    SetDsL3EditRwIp4(V, ipAddr1_f,     p_ds, p_flex_edit->ip_sa.ipv4);
    SetDsL3EditRwIp4(V, protocol_f, p_ds, p_flex_edit->protocol);
    SetDsL3EditRwIp4(V, ttl_f ,     p_ds, p_flex_edit->ttl);

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
    {
        SetDsL3EditRwIp4(V, ipAddr0Valid_f , p_ds, 1 );
        SetDsL3EditRwIp4(V, ipAddr1Valid_f , p_ds, 1 );
        SetDsL3EditRwIp4(V, ipSaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SWAP);
        SetDsL3EditRwIp4(V, ipDaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SWAP);
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA))
    {
        SetDsL3EditRwIp4(V, ipAddr1Valid_f , p_ds, 1 );
        SetDsL3EditRwIp4(V, ipSaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SRC);
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA))
    {
        SetDsL3EditRwIp4(V, ipAddr0Valid_f , p_ds, 1 );
        SetDsL3EditRwIp4(V, ipDaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_DEST);
    }

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TTL))
    {
        SetDsL3EditRwIp4(V, replaceTtl_f, p_ds, 1 );
    }
    else if(CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_DECREASE_TTL))
    {
        SetDsL3EditRwIp4(V, replaceTtl_f, p_ds, 1 );
        SetDsL3EditRwIp4(V, decreaseTtl_f, p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ECN))
    {
        if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_ASSIGN)
        {
            SetDsL3EditRwIp4(V, ecnRemarkMode_f,     p_ds, 1 );
            flex_tos |= (p_flex_edit->ecn & 0x3);
        }
        else if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_MAP)
        {
            SetDsL3EditRwIp4(V, ecnRemarkMode_f,     p_ds, 2 );
        }
    }

    /*1:use assign; 1: map; 3:copy*/
    if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_ASSIGN )
    {
        SetDsL3EditRwIp4(V, dscpRemarkMode_f, p_ds, 1 );
        flex_tos |= ((p_flex_edit->dscp_or_tos & 0x3F) << 2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_MAP )
    {
        SetDsL3EditRwIp4(V, dscpRemarkMode_f, p_ds,  2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_PACKET )
    {
        SetDsL3EditRwIp4(V, dscpRemarkMode_f, p_ds,  3);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_NONE )
    {
        SetDsL3EditRwIp4(V, dscpRemarkMode_f, p_ds,  0);
    }

    SetDsL3EditRwIp4(V, tos_f, p_ds, flex_tos);
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_PROTOCOL))
    {
        SetDsL3EditRwIp4(V, replaceProtocol_f, p_ds, 1 );
    }

    if (p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_ICMP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_CODE))
        {
            SetDsL3EditRwIp4(V, replaceIcmpCode_f, p_ds, 1 );
            SetDsL3EditRwIp4(V, l4Port0Valid_f, p_ds, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_TYPE))
        {
            SetDsL3EditRwIp4(V, replaceIcmpType_f, p_ds, 1 );
            SetDsL3EditRwIp4(V, l4Port1Valid_f, p_ds, 1);
        }
        SetDsL3EditRwIp4(V, l4Port1_f , p_ds, p_flex_edit->icmp_type);
        SetDsL3EditRwIp4(V, l4Port0_f , p_ds, p_flex_edit->icmp_code);

    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_GRE)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_GRE_KEY))
        {
            SetDsL3EditRwIp4(V, replaceGreKey_f, p_ds, 1 );
            SetDsL3EditRwIp4(V, l4Port0Valid_f , p_ds, 1);
            SetDsL3EditRwIp4(V, l4Port1Valid_f , p_ds, 1);
        }

        SetDsL3EditRwIp4(V, l4Port1_f , p_ds, (p_flex_edit->gre_key >> 16));
        SetDsL3EditRwIp4(V, l4Port0_f , p_ds, (p_flex_edit->gre_key & 0xFFFF) );
    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_UDPORTCP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
        {
            SetDsL3EditRwIp4(V, l4Port0Valid_f , p_ds, 1 );
            SetDsL3EditRwIp4(V, l4Port1Valid_f, p_ds, 1 );
            SetDsL3EditRwIp4(V, l4SrcPortReplaceMode_f , p_ds, SYS_L3EDITRW_MODE_SWAP);
            SetDsL3EditRwIp4(V, l4DstPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_SWAP);
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_DST_PORT))
        {
            SetDsL3EditRwIp4(V, l4Port0Valid_f, p_ds, 1 );
            SetDsL3EditRwIp4(V, l4DstPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_DEST);
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_SRC_PORT))
        {
            SetDsL3EditRwIp4(V, l4Port1Valid_f , p_ds, 1 );
            SetDsL3EditRwIp4(V, l4SrcPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_SRC);
        }

        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TCP_PORT))
        {
            SetDsL3EditRwIp4(V, replaceTcpPort_f, p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_UDP_PORT))
        {
            SetDsL3EditRwIp4(V, replaceUdpPort_f, p_ds, 1 );
        }
        SetDsL3EditRwIp4(V, l4Port1_f , p_ds, p_flex_edit->l4_src_port);
        SetDsL3EditRwIp4(V, l4Port0_f , p_ds, p_flex_edit->l4_dst_port);
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_map_l3edit_rwip6(uint8 lchip, ctc_misc_nh_flex_edit_param_t* p_flex_edit, void *p_ds, uint32* p_offset)
{
    uint8 flex_tos = 0;
    ipv6_addr_t ipv6_da;
    ipv6_addr_t ipv6_sa;

    sal_memset(&ipv6_da, 0, sizeof(ipv6_addr_t));
    sal_memset(&ipv6_sa, 0, sizeof(ipv6_addr_t));

    SetDsL3EditRwIp6(V, dsType_f,       p_ds, SYS_NH_DS_TYPE_L3EDIT);
    SetDsL3EditRwIp6(V, l3EditType_f, p_ds, DRV_ENUM(DRV_L3EDITTYPE_RWIP6));
    if (p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_ICMP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_CODE))
        {
            SetDsL3EditRwIp6(V, replaceIcmpCode_f,     p_ds, 1 );
            SetDsL3EditRwIp6(V, l4Port0Valid_f,     p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ICMP_TYPE))
        {
            SetDsL3EditRwIp6(V, replaceIcmpType_f,     p_ds, 1 );
            SetDsL3EditRwIp6(V, l4Port1Valid_f,     p_ds, 1 );
        }
        SetDsL3EditRwIp6(V, l4Port0_f , p_ds, p_flex_edit->icmp_code);
        SetDsL3EditRwIp6(V, l4Port1_f ,  p_ds, p_flex_edit->icmp_type);
    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_GRE)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_GRE_KEY))
        {
            SetDsL3EditRwIp6(V, replaceGreKey_f, p_ds, 1 );
            SetDsL3EditRwIp6(V, l4Port0Valid_f, p_ds, 1 );
            SetDsL3EditRwIp6(V, l4Port1Valid_f, p_ds, 1 );
        }
        SetDsL3EditRwIp6(V, l4Port1_f, p_ds, (p_flex_edit->gre_key >> 16) );
        SetDsL3EditRwIp6(V, l4Port0_f, p_ds, (p_flex_edit->gre_key & 0xFFFF) );
    }
    else if(p_flex_edit->packet_type == CTC_MISC_NH_PACKET_TYPE_UDPORTCP)
    {
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_L4_PORT))
        {
            SetDsL3EditRwIp6(V, l4SrcPortReplaceMode_f , p_ds, SYS_L3EDITRW_MODE_SWAP);
            SetDsL3EditRwIp6(V, l4DstPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_SWAP);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_DST_PORT))
        {
            SetDsL3EditRwIp6(V, l4DstPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_DEST);
            SetDsL3EditRwIp6(V, l4Port0Valid_f, p_ds, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_L4_SRC_PORT))
        {
            SetDsL3EditRwIp6(V, l4SrcPortReplaceMode_f, p_ds, SYS_L3EDITRW_MODE_SRC);
            SetDsL3EditRwIp6(V, l4Port1Valid_f, p_ds, 1);
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TCP_PORT))
        {
            SetDsL3EditRwIp6(V, replaceTcpPort_f, p_ds, 1 );
        }
        if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_UDP_PORT))
        {
            SetDsL3EditRwIp6(V, replaceUdpPort_f, p_ds, 1 );
        }
        SetDsL3EditRwIp6(V, l4Port1_f , p_ds, p_flex_edit->l4_src_port);
        SetDsL3EditRwIp6(V, l4Port0_f , p_ds, p_flex_edit->l4_dst_port);
    }


    ipv6_da[0] = p_flex_edit->ip_da.ipv6[3];
    ipv6_da[1] = p_flex_edit->ip_da.ipv6[2];
    ipv6_da[2] = p_flex_edit->ip_da.ipv6[1];
    ipv6_da[3] = p_flex_edit->ip_da.ipv6[0];
    ipv6_sa[0] = p_flex_edit->ip_sa.ipv6[3];
    ipv6_sa[1] = p_flex_edit->ip_sa.ipv6[2];
    ipv6_sa[2] = p_flex_edit->ip_sa.ipv6[1];
    ipv6_sa[3] = p_flex_edit->ip_sa.ipv6[0];
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_SWAP_IP))
    {
        SetDsL3EditRwIp6(V, ipSaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SWAP);
        SetDsL3EditRwIp6(V, ipDaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SWAP);
    }
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPDA))
    {
        SetDsL3EditRwIp6(V, ipDaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_DEST);
        SetDsL3EditRwIp6(V, ipAddr0Valid_f ,     p_ds, 1);
    }
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_IPSA))
    {
        SetDsL3EditRwIp6(V, ipSaReplaceMode_f ,     p_ds, SYS_L3EDITRW_MODE_SRC);
        SetDsL3EditRwIp6(V, ipAddr1Valid_f ,     p_ds, 1);
    }
    SetDsL3EditRwIp6(A, ipAddr0_f,         p_ds,  ipv6_da);
    SetDsL3EditRwIp6(A, ipAddr1_f,         p_ds,  ipv6_sa);

    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_PROTOCOL))
    {
        SetDsL3EditRwIp6(V, replaceProtocol_f,     p_ds, 1 );
        SetDsL3EditRwIp6(V, protocol_f ,  p_ds, p_flex_edit->protocol);
    }

    SetDsL3EditRwIp6(V, ttl_f ,        p_ds, p_flex_edit->ttl);
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_TTL))
    {
        SetDsL3EditRwIp6(V, replaceTtl_f,     p_ds, 1 );
    }
    else if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_DECREASE_TTL))
    {
        SetDsL3EditRwIp6(V, replaceTtl_f, p_ds, 1 );
        SetDsL3EditRwIp6(V, decreaseTtl_f,     p_ds, 1 );
    }
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_ECN))
    {
        if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_ASSIGN)
        {
            SetDsL3EditRwIp6(V, ecnRemarkMode_f,     p_ds, 1 );
            flex_tos |= (p_flex_edit->ecn & 0x3);
        }
        else if (p_flex_edit->ecn_select == CTC_NH_ECN_SELECT_MAP)
        {
            SetDsL3EditRwIp6(V, ecnRemarkMode_f,     p_ds, 2 );
        }
    }
    if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_ASSIGN )
    {
        SetDsL3EditRwIp6(V, dscpRemarkMode_f ,     p_ds, 1 );
        flex_tos |= ((p_flex_edit->dscp_or_tos & 0x3F) << 2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_MAP )
    {
        SetDsL3EditRwIp6(V, dscpRemarkMode_f,     p_ds,  2);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_PACKET )
    {
        SetDsL3EditRwIp6(V, dscpRemarkMode_f,     p_ds,  3);
    }
    else if (p_flex_edit->dscp_select == CTC_NH_DSCP_SELECT_NONE )
    {
        SetDsL3EditRwIp6(V, dscpRemarkMode_f,     p_ds,  0);
    }
    SetDsL3EditRwIp6(V, tos_f,     p_ds, flex_tos);
    CTC_MAX_VALUE_CHECK(p_flex_edit->flow_label, 0xFFFFF);
    SetDsL3EditRwIp6(V, flowLabel_f ,     p_ds, p_flex_edit->flow_label&0xFFFFF);
    if (CTC_FLAG_ISSET(p_flex_edit->flag, CTC_MISC_NH_FLEX_EDIT_REPLACE_FLOW_LABEL))
    {
        SetDsL3EditRwIp6(V, replaceFlowLabel_f,     p_ds, 1 );
    }

    return CTC_E_NONE;

}


int32
sys_usw_nh_map_l3edit_rwip41x_nat(uint8 lchip, sys_dsl3edit_nat4w_t* p_sys_nat, void *p_ds, uint32* p_offset)
{
    SetDsL3EditRwIp41X(V, discardType_f,           p_ds,   0);
    SetDsL3EditRwIp41X(V, discard_f,               p_ds,   0);
    SetDsL3EditRwIp41X(V, dsType_f,                p_ds,   p_sys_nat->ds_type);
    SetDsL3EditRwIp41X(V, l3EditType_f,         p_ds,   p_sys_nat->l3_rewrite_type);
    SetDsL3EditRwIp41X(V, replaceUdpPort_f,     p_ds,   1);
    SetDsL3EditRwIp41X(V, replaceTcpPort_f,     p_ds,   1);
    SetDsL3EditRwIp41X(V, l4SrcPortReplaceMode_f,     p_ds,   p_sys_nat->replace_l4_src_port);
    SetDsL3EditRwIp41X(V, ipSaReplaceMode_f,     p_ds,   p_sys_nat->replace_ip_sa);
    SetDsL3EditRwIp41X(V, l4DstPortReplaceMode_f,     p_ds,   1);
    SetDsL3EditRwIp41X(V, ipDaReplaceMode_f,     p_ds,   p_sys_nat->replace_ip_da);
    SetDsL3EditRwIp41X(V, ipAddr0_f,                  p_ds,   p_sys_nat->ip);
    SetDsL3EditRwIp41X(V, ipAddr0Valid_f,                  p_ds,   1);
    SetDsL3EditRwIp41X(V, l4Port0_f,                  p_ds,   p_sys_nat->l4_port);
    SetDsL3EditRwIp41X(V, l4Port0Valid_f,                  p_ds,   p_sys_nat->l4_port? 1: 0);
    SetDsL3EditRwIp41X(V, nextEditPtrValid_f,      p_ds,   p_sys_nat->out_l2edit_valid);
    SetDsL3EditRwIp41X(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditRwIp41X(V, outerEditPtr_f,          p_ds,   p_sys_nat->l2edit_ptr);
    if (p_sys_nat->out_l2edit_valid && (p_sys_nat->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditRwIp41X(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditRwIp41X(V, outerEditPtr_f,          p_ds,   (p_sys_nat->l2edit_ptr - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_rwip41x_nat(uint8 lchip, sys_dsl3edit_nat4w_t* p_sys_nat, void *p_ds)
{
    p_sys_nat->ds_type = GetDsL3EditRwIp41X(V, dsType_f, p_ds);
    p_sys_nat->l3_rewrite_type = GetDsL3EditRwIp41X(V, l3EditType_f, p_ds);
    p_sys_nat->replace_l4_src_port = GetDsL3EditRwIp41X(V, l4SrcPortReplaceMode_f, p_ds);
    p_sys_nat->replace_ip_sa = GetDsL3EditRwIp41X(V, ipSaReplaceMode_f, p_ds);
    p_sys_nat->replace_l4_dest_port = GetDsL3EditRwIp41X(V, l4DstPortReplaceMode_f, p_ds);
    p_sys_nat->replace_ip_da = GetDsL3EditRwIp41X(V, ipDaReplaceMode_f, p_ds);
    p_sys_nat->ip = GetDsL3EditRwIp41X(V, ipAddr0_f, p_ds);
    p_sys_nat->l4_port = GetDsL3EditRwIp41X(V, l4Port0_f, p_ds);
    p_sys_nat->out_l2edit_valid = GetDsL3EditRwIp41X(V, nextEditPtrValid_f, p_ds);
    p_sys_nat->l2edit_ptr = GetDsL3EditRwIp41X(V, outerEditPtr_f, p_ds);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_rwip4_nat(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds, uint32* p_offset)
{
    SetDsL3EditRwIp4(V, discardType_f,           p_ds,   0);
    SetDsL3EditRwIp4(V, discard_f,               p_ds,   0);
    SetDsL3EditRwIp4(V, dsType_f,                p_ds,   p_sys_nat->ds_type);
    SetDsL3EditRwIp4(V, l3EditType_f,         p_ds,   p_sys_nat->l3_rewrite_type);
    SetDsL3EditRwIp4(V, replaceUdpPort_f,     p_ds,   1);
    SetDsL3EditRwIp4(V, replaceTcpPort_f,     p_ds,   1);
    SetDsL3EditRwIp4(V, ipSaReplaceMode_f,     p_ds,   p_sys_nat->replace_ip_sa? SYS_L3EDITRW_MODE_SRC : 0);
    SetDsL3EditRwIp4(V, ipAddr1_f,                  p_ds,   p_sys_nat->ipda[0]);
    SetDsL3EditRwIp4(V, ipAddr1Valid_f,                  p_ds,   1);
    if (p_sys_nat->sub_net)
    {
        SetDsL3EditRwIp4(V, ipDaReplaceMode_f,          p_ds,   p_sys_nat->replace_ip_da);
        SetDsL3EditRwIp4(V, ipAddr0_f,                  p_ds,   p_sys_nat->mask[0]);
        SetDsL3EditRwIp4(V, ipAddr0Valid_f,             p_ds,   1);
        SetDsL3EditRwIp4(V, ipAddr0Type_f,              p_ds,   1);
    }
    SetDsL3EditRwIp4(V, l4SrcPortReplaceMode_f,     p_ds,   p_sys_nat->replace_l4_src_port ? SYS_L3EDITRW_MODE_SRC : 0);
    SetDsL3EditRwIp4(V, l4Port1_f,                  p_ds,   p_sys_nat->l4_src_port);
    SetDsL3EditRwIp4(V, l4Port1Valid_f,                  p_ds,   p_sys_nat->l4_src_port ? 1 : 0);
    SetDsL3EditRwIp6(V, l4DstPortReplaceMode_f, p_ds,   SYS_L3EDITRW_MODE_DEST);
    SetDsL3EditRwIp4(V, l4Port0_f,                  p_ds,   p_sys_nat->l4_dest_port);
    SetDsL3EditRwIp4(V, l4Port0Valid_f,                  p_ds,   p_sys_nat->l4_dest_port ? 1 : 0);
    SetDsL3EditRwIp4(V, nextEditPtrValid_f,     p_ds,   p_sys_nat->out_l2edit_valid);
    SetDsL3EditRwIp4(V, outerEditPtrType_f,     p_ds,   0);
    SetDsL3EditRwIp4(V, outerEditPtr_f,         p_ds,   p_sys_nat->l2edit_ptr);
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_rwip4_nat(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds)
{
    p_sys_nat->ds_type = GetDsL3EditRwIp4(V, dsType_f, p_ds);
    p_sys_nat->l3_rewrite_type = GetDsL3EditRwIp4(V, l3EditType_f, p_ds);
    if (GetDsL3EditRwIp4(V, l4SrcPortReplaceMode_f, p_ds))
    {
        p_sys_nat->replace_l4_src_port = 1;
    }
    if (GetDsL3EditRwIp4(V, ipSaReplaceMode_f, p_ds))
    {
        p_sys_nat->replace_ip_sa = 1;
    }
    if (GetDsL3EditRwIp4(V, ipAddr0Type_f, p_ds))
    {
        p_sys_nat->sub_net = 1;
        p_sys_nat->mask[0] = GetDsL3EditRwIp4(V, ipAddr0_f, p_ds);
    }
    p_sys_nat->ipda[0] = GetDsL3EditRwIp4(V, ipAddr1_f, p_ds);
    p_sys_nat->l4_src_port = GetDsL3EditRwIp4(V, l4Port1_f, p_ds);
    p_sys_nat->l4_dest_port = GetDsL3EditRwIp4(V, l4Port0_f, p_ds);
    p_sys_nat->out_l2edit_valid = GetDsL3EditRwIp4(V, nextEditPtrValid_f, p_ds);
    p_sys_nat->l2edit_ptr = GetDsL3EditRwIp4(V, outerEditPtr_f, p_ds);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_rwip6_nat(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds, uint32* p_offset)
{
    SetDsL3EditRwIp6(V, discardType_f,          p_ds,   0);
    SetDsL3EditRwIp6(V, discard_f,              p_ds,   0);
    SetDsL3EditRwIp6(V, dsType_f,               p_ds,   p_sys_nat->ds_type);
    SetDsL3EditRwIp6(V, l3EditType_f,           p_ds,   p_sys_nat->l3_rewrite_type);
    SetDsL3EditRwIp6(V, replaceUdpPort_f,       p_ds,   1);
    SetDsL3EditRwIp6(V, replaceTcpPort_f,       p_ds,   1);
    SetDsL3EditRwIp6(V, ipSaReplaceMode_f,      p_ds,   p_sys_nat->replace_ip_sa);
    if (p_sys_nat->sub_net)
    {
        SetDsL3EditRwIp6(V, ipDaReplaceMode_f,      p_ds,   p_sys_nat->replace_ip_da);
        SetDsL3EditRwIp6(A, ipAddr1_f,              p_ds,   p_sys_nat->ipda);
        SetDsL3EditRwIp6(V, ipAddr1Valid_f,         p_ds,   1);
        SetDsL3EditRwIp6(A, ipAddr0_f,              p_ds,   p_sys_nat->mask);
        SetDsL3EditRwIp6(V, ipAddr0Valid_f,         p_ds,   1);
        SetDsL3EditRwIp6(V, ipAddr0Type_f,         p_ds,   1);
    }
    else
    {
        SetDsL3EditRwIp6(V, ipDaReplaceMode_f,      p_ds,   p_sys_nat->replace_ip_da? SYS_L3EDITRW_MODE_DEST : 0);
        SetDsL3EditRwIp6(A, ipAddr0_f,              p_ds,   p_sys_nat->ipda);
        SetDsL3EditRwIp6(V, ipAddr0Valid_f,         p_ds,   1);
    }
    SetDsL3EditRwIp6(V, l4SrcPortReplaceMode_f,     p_ds,   p_sys_nat->replace_l4_src_port ? SYS_L3EDITRW_MODE_SRC : 0);
    SetDsL3EditRwIp6(V, l4Port1_f,                  p_ds,   p_sys_nat->l4_src_port);
    SetDsL3EditRwIp6(V, l4Port1Valid_f,                  p_ds,   p_sys_nat->l4_src_port ? 1 : 0);
    SetDsL3EditRwIp6(V, l4DstPortReplaceMode_f, p_ds,   SYS_L3EDITRW_MODE_DEST);
    SetDsL3EditRwIp6(V, l4Port0_f,                  p_ds,   p_sys_nat->l4_dest_port);
    SetDsL3EditRwIp6(V, l4Port0Valid_f,                  p_ds,  p_sys_nat->l4_dest_port ? 1 : 0);
    SetDsL3EditRwIp6(V, nextEditPtrValid_f,     p_ds,   p_sys_nat->out_l2edit_valid);
    SetDsL3EditRwIp6(V, outerEditPtrType_f,     p_ds,   0);
    SetDsL3EditRwIp6(V, outerEditPtr_f,         p_ds,   p_sys_nat->l2edit_ptr);
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_rwip6_nat(uint8 lchip, sys_dsl3edit_nat8w_t* p_sys_nat, void *p_ds)
{
    p_sys_nat->ds_type = GetDsL3EditRwIp6(V, dsType_f, p_ds);
    p_sys_nat->l3_rewrite_type = GetDsL3EditRwIp6(V, l3EditType_f, p_ds);
    if (GetDsL3EditRwIp6(V, l4SrcPortReplaceMode_f, p_ds))
    {
        p_sys_nat->replace_l4_src_port = 1;
    }
    if (GetDsL3EditRwIp6(V, l4Port0Valid_f, p_ds))
    {
        p_sys_nat->replace_l4_dest_port = 1;
    }
    if (GetDsL3EditRwIp6(V, ipSaReplaceMode_f, p_ds))
    {
        p_sys_nat->replace_ip_sa = 1;
    }
    if (GetDsL3EditRwIp6(V, ipAddr0Type_f, p_ds))
    {
        GetDsL3EditRwIp6(A, ipAddr1_f, p_ds, p_sys_nat->ipda);
        GetDsL3EditRwIp6(A, ipAddr0_f, p_ds, p_sys_nat->mask);
        p_sys_nat->sub_net = 1;
    }
    else
    {
        GetDsL3EditRwIp6(A, ipAddr0_f, p_ds, p_sys_nat->ipda);
    }
    p_sys_nat->out_l2edit_valid = GetDsL3EditRwIp6(V, nextEditPtrValid_f, p_ds);
    p_sys_nat->l2edit_ptr = GetDsL3EditRwIp6(V, outerEditPtr_f, p_ds);
    p_sys_nat->l4_src_port = GetDsL3EditRwIp6(V, l4Port1_f, p_ds);
    p_sys_nat->l4_dest_port = GetDsL3EditRwIp6(V, l4Port0_f, p_ds);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_addip6_sr(uint8 lchip, sys_dsl3edit_srv6_t* p_sys_addip6sr, void *p_ds, uint32* p_offset)
{
    SetDsL3EditAddIp6Sr(V, autoIpProtocolTypeMode_f,p_ds,   1);
    SetDsL3EditAddIp6Sr(V, ecnCopyMode_f,           p_ds,   p_sys_addip6sr->ecn_mode);
    SetDsL3EditAddIp6Sr(V, dsType_f,                p_ds,   p_sys_addip6sr->ds_type);
    SetDsL3EditAddIp6Sr(V, l3EditType_f,            p_ds,   p_sys_addip6sr->l3_rewrite_type);
    SetDsL3EditAddIp6Sr(V, nextEditPtrValid_f,      p_ds,   p_sys_addip6sr->out_l2edit_valid);
    SetDsL3EditAddIp6Sr(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditAddIp6Sr(V, outerEditPtr_f,          p_ds,   p_sys_addip6sr->out_l2edit_valid ? (p_sys_addip6sr->l2edit_ptr) : 0);
    SetDsL3EditAddIp6Sr(V, mtuCheckEn_f,            p_ds,   p_sys_addip6sr->mtu_check_en);
    SetDsL3EditAddIp6Sr(V, mtuSize_f,               p_ds,   p_sys_addip6sr->mtu_size);
    SetDsL3EditAddIp6Sr(V, mapTtl_f,                p_ds,   p_sys_addip6sr->map_ttl);
    SetDsL3EditAddIp6Sr(V, ttl_f,                   p_ds,   p_sys_addip6sr->ttl);
	SetDsL3EditAddIp6Sr(V, ipSaIndex_f,             p_ds,   p_sys_addip6sr->ipsa_index);
    if(DRV_FROM_AT(lchip))
    {
        if (p_sys_addip6sr->new_flow_label_valid)
        {
            SetDsL3EditAddIp6Sr(V, newFlowLabelValid_f,     p_ds,   p_sys_addip6sr->new_flow_label_valid);
            SetDsL3EditAddIp6Sr(V, newFlowLabelMode_f,      p_ds,   p_sys_addip6sr->new_flow_label_mode);
            SetDsL3EditAddIp6Sr(V, flowLabel_f,              p_ds,   p_sys_addip6sr->flow_label);
        }
        SetDsL3EditAddIp6Sr(V, statsPtr_f,              p_ds,   p_sys_addip6sr->stats_ptr);
    }
    else
    {
        if (p_sys_addip6sr->new_flow_label_valid)
        {
            SetDsL3EditAddIp6Sr(V, newFlowLabelValid_f,     p_ds,   p_sys_addip6sr->new_flow_label_valid);
            SetDsL3EditAddIp6Sr(V, newFlowLabelMode_f,      p_ds,   p_sys_addip6sr->new_flow_label_mode);
            SetDsL3EditAddIp6Sr(V, statsPtr_f,              p_ds,   p_sys_addip6sr->flow_label);
            SetDsL3EditAddIp6Sr(V, statsPtrMode_f,      p_ds,   1);
        }
        else
        {
            SetDsL3EditAddIp6Sr(V, statsPtr_f,              p_ds,   p_sys_addip6sr->stats_ptr);
            SetDsL3EditAddIp6Sr(V, statsPtrMode_f,      p_ds,   0);
        }
    }

    SetDsL3EditAddIp6Sr(V, packetLengthType_f,      p_ds,   1);
    SetDsL3EditAddIp6Sr(V, dscpRemarkMode_f,        p_ds,   p_sys_addip6sr->derive_dscp);
    if (p_sys_addip6sr->derive_dscp == 1)
    {
        SetDsL3EditAddIp6Sr(V, uDscpPhb_gRaw_dscp_f,    p_ds,   (p_sys_addip6sr->tos>>2));
    }
    else if (p_sys_addip6sr->derive_dscp == 2)
    {
        SetDsL3EditAddIp6Sr(V, uDscpPhb_gPtr_dscpPhbPtr_f,     p_ds,   p_sys_addip6sr->dscp_domain);
    }
    SetDsL3EditAddIp6Sr(V, nextHeader_f,            p_ds,   p_sys_addip6sr->next_header);
    SetDsL3EditAddIp6Sr(V, nextHeaderEn_f,          p_ds,   p_sys_addip6sr->next_header_en);
    SetDsL3EditAddIp6Sr(V, headerType_f,            p_ds,   p_sys_addip6sr->header_type);
    SetDsL3EditAddIp6Sr(V, ipProtocolType_f,        p_ds,   143);
    SetDsL3EditAddIp6Sr(V, routingType_f,           p_ds,   4);
    SetDsL3EditAddIp6Sr(V, flags_f,                 p_ds,   0);
    SetDsL3EditAddIp6Sr(V, tag_f,                   p_ds,   0);
    SetDsL3EditAddIp6Sr(A, ipDa_f,                  p_ds,   p_sys_addip6sr->vpn_sid); /*EpePktProcCtl.sr6IpSaMode = 0*/
    SetDsL3EditAddIp6Sr(A, reducedFirstSegment_f,   p_ds,   p_sys_addip6sr->ipda);
    SetDsL3EditAddIp6Sr(V, replaceLastSegmentAsPR_f,p_ds,   p_sys_addip6sr->replace_last);
    if (p_sys_addip6sr->out_l2edit_valid && (p_sys_addip6sr->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditAddIp6Sr(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditAddIp6Sr(V, outerEditPtr_f,          p_ds,   (p_sys_addip6sr->l2edit_ptr - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    SetDsL3EditAddIp6Sr(V, xEditPtr_f,              p_ds,   p_sys_addip6sr->xedit_ptr);

    return CTC_E_NONE;
}
int32
sys_usw_nh_unmap_l3edit_addip6_sr(uint8 lchip, sys_dsl3edit_srv6_t* p_sys_addip6sr, void *ds)
{
    p_sys_addip6sr->ecn_mode = GetDsL3EditAddIp6Sr(V, ecnCopyMode_f, ds);
    p_sys_addip6sr->ds_type = GetDsL3EditAddIp6Sr(V, dsType_f, ds);
    p_sys_addip6sr->l3_rewrite_type = GetDsL3EditAddIp6Sr(V, l3EditType_f, ds);
    p_sys_addip6sr->out_l2edit_valid = GetDsL3EditAddIp6Sr(V, nextEditPtrValid_f, ds);
    p_sys_addip6sr->l2edit_ptr = GetDsL3EditAddIp6Sr(V, outerEditPtr_f, ds);
    p_sys_addip6sr->mtu_check_en = GetDsL3EditAddIp6Sr(V, mtuCheckEn_f, ds);
    p_sys_addip6sr->mtu_size = GetDsL3EditAddIp6Sr(V, mtuSize_f, ds);
    p_sys_addip6sr->map_ttl = GetDsL3EditAddIp6Sr(V, mapTtl_f, ds);
    p_sys_addip6sr->ttl = GetDsL3EditAddIp6Sr(V, ttl_f, ds);
    if(DRV_FROM_AT(lchip))
    {
        p_sys_addip6sr->new_flow_label_valid = GetDsL3EditAddIp6Sr(V, newFlowLabelValid_f, ds);
        p_sys_addip6sr->new_flow_label_mode = GetDsL3EditAddIp6Sr(V, newFlowLabelMode_f, ds);
        p_sys_addip6sr->flow_label =  GetDsL3EditAddIp6Sr(V, flowLabel_f, ds);
        p_sys_addip6sr->stats_ptr = GetDsL3EditAddIp6Sr(V, statsPtr_f, ds);
    }
    else
    {
        if (GetDsL3EditAddIp6Sr(V, statsPtrMode_f, ds))
        {
            p_sys_addip6sr->new_flow_label_valid = GetDsL3EditAddIp6Sr(V, newFlowLabelValid_f, ds);
            p_sys_addip6sr->new_flow_label_mode = GetDsL3EditAddIp6Sr(V, newFlowLabelMode_f, ds);
            p_sys_addip6sr->flow_label =  GetDsL3EditAddIp6Sr(V, statsPtr_f, ds);
        }
        else
        {
            p_sys_addip6sr->stats_ptr = GetDsL3EditAddIp6Sr(V, statsPtr_f, ds);
        }
    }

    p_sys_addip6sr->derive_dscp = GetDsL3EditAddIp6Sr(V, dscpRemarkMode_f, ds);
    if (p_sys_addip6sr->derive_dscp == 1)
    {
        p_sys_addip6sr->tos = GetDsL3EditAddIp6Sr(V, uDscpPhb_gRaw_dscp_f, ds) << 2;
    }
    else if (p_sys_addip6sr->derive_dscp == 2)
    {
        p_sys_addip6sr->dscp_domain = GetDsL3EditAddIp6Sr(V, uDscpPhb_gPtr_dscpPhbPtr_f, ds);
    }
    p_sys_addip6sr->next_header = GetDsL3EditAddIp6Sr(V, nextHeader_f, ds);
    p_sys_addip6sr->next_header_en = GetDsL3EditAddIp6Sr(V, nextHeaderEn_f, ds);
    p_sys_addip6sr->header_type = GetDsL3EditAddIp6Sr(V, headerType_f, ds);
    p_sys_addip6sr->replace_last = GetDsL3EditAddIp6Sr(V, replaceLastSegmentAsPR_f, ds);
    p_sys_addip6sr->ipsa_index = GetDsL3EditAddIp6Sr(V, ipSaIndex_f, ds);
    GetDsL3EditAddIp6Sr(A, ipDa_f, ds, p_sys_addip6sr->vpn_sid);
    GetDsL3EditAddIp6Sr(A, reducedFirstSegment_f, ds, p_sys_addip6sr->ipda);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_rwip6_sr(uint8 lchip, sys_dsl3edit_srv6_t* p_sys_rwip6sr, void *p_ds, uint32* p_offset)
{
    ipv6_addr_t vpnsid_tmp;

    sal_memset(&vpnsid_tmp, 0, sizeof(ipv6_addr_t));

    SetDsL3EditRwIp6Sr(V, dsType_f,                p_ds,   p_sys_rwip6sr->ds_type);
    SetDsL3EditRwIp6Sr(V, l3EditType_f,            p_ds,   p_sys_rwip6sr->l3_rewrite_type);
    SetDsL3EditRwIp6Sr(V, nextEditPtrValid_f,      p_ds,   p_sys_rwip6sr->out_l2edit_valid);
    SetDsL3EditRwIp6Sr(V, outerEditPtrType_f,      p_ds,   0);
    SetDsL3EditRwIp6Sr(V, outerEditPtr_f,          p_ds,   (p_sys_rwip6sr->out_l2edit_valid ? (p_sys_rwip6sr->l2edit_ptr) : 0));
    if (p_sys_rwip6sr->map_ttl || p_sys_rwip6sr->ttl)
    {
        SetDsL3EditRwIp6Sr(V, replaceTtl_f,        p_ds,   1);
        SetDsL3EditRwIp6Sr(V, decreaseTtl_f,       p_ds,   p_sys_rwip6sr->map_ttl);
        SetDsL3EditRwIp6Sr(V, ttl_f,               p_ds,   p_sys_rwip6sr->ttl);
    }
    SetDsL3EditRwIp6Sr(V, statsPtr_f,              p_ds,   p_sys_rwip6sr->stats_ptr);
    SetDsL3EditRwIp6Sr(V, replaceFlowLabel_f,      p_ds,   p_sys_rwip6sr->new_flow_label_valid);
    SetDsL3EditRwIp6Sr(V, replaceFlowLabelMode_f,  p_ds,   p_sys_rwip6sr->new_flow_label_mode);
    SetDsL3EditRwIp6Sr(V, flowLabel_f,             p_ds,   p_sys_rwip6sr->flow_label);
    SetDsL3EditRwIp6Sr(V, dscpRemarkMode_f,        p_ds,   p_sys_rwip6sr->derive_dscp);
    SetDsL3EditRwIp6Sr(V, tos_f,                   p_ds,   p_sys_rwip6sr->tos);
    SetDsL3EditRwIp6Sr(V, ecnRemarkMode_f,         p_ds,   p_sys_rwip6sr->ecn_mode);
    SetDsL3EditRwIp6Sr(V, nextHeader_f,            p_ds,   p_sys_rwip6sr->next_header);
    SetDsL3EditRwIp6Sr(V, nextHeaderEn_f,          p_ds,   p_sys_rwip6sr->next_header_en);
    SetDsL3EditRwIp6Sr(V, headerType_f,            p_ds,   p_sys_rwip6sr->header_type);
    SetDsL3EditRwIp6Sr(V, routingType_f,           p_ds,   4);
    SetDsL3EditRwIp6Sr(V, ipDaReplaceMode_f,       p_ds,   SYS_L3EDITRW_MODE_DEST);
    SetDsL3EditRwIp6Sr(V, flags_f,                 p_ds,   0);
    SetDsL3EditRwIp6Sr(V, tag_f,                   p_ds,   0);
    SetDsL3EditRwIp6Sr(A, reducedFirstSegment_f,   p_ds,   p_sys_rwip6sr->ipda);
    SetDsL3EditRwIp6Sr(A, ipAddr0_f,               p_ds,   p_sys_rwip6sr->vpn_sid);
    SetDsL3EditRwIp6Sr(V, ipAddr0Valid_f,          p_ds,   (sal_memcmp(p_sys_rwip6sr->vpn_sid, vpnsid_tmp, sizeof(ipv6_addr_t)) ? 1 : 0));
    SetDsL3EditRwIp6Sr(V, ipDaReplaceMode_f,       p_ds,   SYS_L3EDITRW_MODE_DEST);
    SetDsL3EditRwIp6Sr(V, replaceLastSegmentAsPR_f,p_ds,   p_sys_rwip6sr->replace_last);
    SetDsL3EditRwIp6Sr(V, l4ChksumMaskId_f,        p_ds,   (p_sys_rwip6sr->upd_chksum ? SYS_L4CHKSUM_ENABLE_UPDATE_FOR_SRV6 : SYS_L4CHKSUM_DISABLE_UPDATE_FOR_SRV6));
    if (p_sys_rwip6sr->out_l2edit_valid && (p_sys_rwip6sr->l2edit_ptr >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        /*use spme resource to edit ARP*/
        SetDsL3EditRwIp6Sr(V, nextEditPtrValid_f,      p_ds,   0);
        SetDsL3EditRwIp6Sr(V, outerEditPtr_f,          p_ds,   (p_sys_rwip6sr->l2edit_ptr - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)));
    }
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_l3edit_rwip6_sr(uint8 lchip, sys_dsl3edit_srv6_t* p_sys_rwip6sr, void *ds)
{
    p_sys_rwip6sr->ds_type = GetDsL3EditRwIp6Sr(V, dsType_f, ds);
    p_sys_rwip6sr->l3_rewrite_type =  GetDsL3EditRwIp6Sr(V, l3EditType_f, ds);
    p_sys_rwip6sr->out_l2edit_valid = GetDsL3EditRwIp6Sr(V, nextEditPtrValid_f, ds);
    p_sys_rwip6sr->l2edit_ptr = GetDsL3EditRwIp6Sr(V, outerEditPtr_f, ds);
    if (GetDsL3EditRwIp6Sr(V, replaceTtl_f, ds))
    {
        p_sys_rwip6sr->map_ttl = GetDsL3EditRwIp6Sr(V, decreaseTtl_f, ds);
        p_sys_rwip6sr->ttl = GetDsL3EditRwIp6Sr(V, ttl_f, ds);
    }
    p_sys_rwip6sr->stats_ptr = GetDsL3EditRwIp6Sr(V, statsPtr_f, ds);
    p_sys_rwip6sr->new_flow_label_valid = GetDsL3EditRwIp6Sr(V, replaceFlowLabel_f, ds);
    p_sys_rwip6sr->new_flow_label_mode =  GetDsL3EditRwIp6Sr(V, replaceFlowLabelMode_f, ds);
    p_sys_rwip6sr->flow_label = GetDsL3EditRwIp6Sr(V, flowLabel_f, ds);
    p_sys_rwip6sr->derive_dscp = GetDsL3EditRwIp6Sr(V, dscpRemarkMode_f, ds);
    p_sys_rwip6sr->tos = GetDsL3EditRwIp6Sr(V, tos_f, ds);
    p_sys_rwip6sr->ecn_mode = GetDsL3EditRwIp6Sr(V, ecnRemarkMode_f, ds);
    p_sys_rwip6sr->next_header = GetDsL3EditRwIp6Sr(V, nextHeader_f, ds);
    p_sys_rwip6sr->next_header_en = GetDsL3EditRwIp6Sr(V, nextHeaderEn_f, ds);
    p_sys_rwip6sr->header_type = GetDsL3EditRwIp6Sr(V, headerType_f, ds);
    p_sys_rwip6sr->upd_chksum = (SYS_L4CHKSUM_DISABLE_UPDATE_FOR_SRV6 == GetDsL3EditRwIp6Sr(V, l4ChksumMaskId_f, ds)) ? 0 : 1;
    GetDsL3EditRwIp6Sr(A, reducedFirstSegment_f, ds, p_sys_rwip6sr->ipda);
    GetDsL3EditRwIp6Sr(A, ipAddr0_f, ds, p_sys_rwip6sr->vpn_sid);
    p_sys_rwip6sr->replace_last = GetDsL3EditRwIp6Sr(V, replaceLastSegmentAsPR_f, ds);
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_l3edit_srh(uint8 lchip, sys_dsl3edit_srh_t* p_sys_srh, void *p_ds, uint32* p_offset)
{
    SetDsL3EditAddIp6ExtHeader(V, l3EditType_f,                p_ds,   DRV_ENUM(DRV_L3EDITTYPE_ADDIP68X));
    SetDsL3EditAddIp6ExtHeader(V, extHeaderLen_f,              p_ds,   p_sys_srh->header_len);
    SetDsL3EditAddIp6ExtHeader(V, replacePRAsFirstSegment_f,   p_ds,   p_sys_srh->replace_ipda);
    SetDsL3EditAddIp6ExtHeader(V, lastEntry_f,                 p_ds,   p_sys_srh->last_entry);
    SetDsL3EditAddIp6ExtHeader(V, segmentLeft_f,               p_ds,   p_sys_srh->segment_left);
    SetDsL3EditAddIp6ExtHeader(A, segment0_f,                  p_ds,   p_sys_srh->sid_list[0]);
    SetDsL3EditAddIp6ExtHeader(A, segment1_f,                  p_ds,   p_sys_srh->sid_list[1]);
    SetDsL3EditAddIp6ExtHeader(A, segment2_f,                  p_ds,   p_sys_srh->sid_list[2]);
    SetDsL3EditAddIp6ExtHeader(V, nextEditPtrValid_f,          p_ds,   p_sys_srh->out_l2edit_valid);
    SetDsL3EditAddIp6ExtHeader(V, outerEditPtrType_f,          p_ds,   0);
    SetDsL3EditAddIp6ExtHeader(V, outerEditPtr_f,              p_ds,   p_sys_srh->out_l2edit_valid ? (p_sys_srh->l2edit_ptr) : 0);
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_l3edit_addraw(uint8 lchip, sys_dsl3edit_raw_t* p_sys_l3edit, void *p_ds, uint32* p_offset)
{
    SetDsL3EditAddRaw(V, discardType_f,        p_ds,  0);
    SetDsL3EditAddRaw(V, discard_f,            p_ds,  0);
    SetDsL3EditAddRaw(V, dsType_f,             p_ds,  0);
    SetDsL3EditAddRaw(V, l3EditType_f,         p_ds,  DRV_ENUM(DRV_L3EDITTYPE_ADDRAW));
    SetDsL3EditAddRaw(V, nextEditPtrValid_f,   p_ds,  0);
    SetDsL3EditAddRaw(V, outerEditPtrType_f,   p_ds,  0);
    SetDsL3EditAddRaw(V, outerEditPtr_f,       p_ds,  0);

    SetDsL3EditAddRaw(V, packetType_f,         p_ds,  7);
    if (p_sys_l3edit)
    {
        SetDsL3EditAddRaw(V, rewriteByteNum_f,     p_ds,  p_sys_l3edit->data_len);
        SetDsL3EditAddRaw(A, rewriteString_f,      p_ds,  p_sys_l3edit->data);
    }
    SetDsL3EditAddRaw(V, xEditPtr_f,           p_ds,  0);

    return CTC_E_NONE;
}
int32
sys_usw_nh_unmap_l3edit_addraw(uint8 lchip, sys_dsl3edit_raw_t* p_sys_l3edit, void *p_ds)
{
    p_sys_l3edit->data_len = GetDsL3EditAddRaw(V, rewriteByteNum_f, p_ds);
    GetDsL3EditAddRaw(A, rewriteString_f, p_ds, p_sys_l3edit->data);
    return CTC_E_NONE;
}

int32
sys_usw_nh_map_l3edit_fp(uint8 lchip, sys_dsl3edit_fp_t* p_sys_fp, void *p_ds, uint32* p_offset)
{
    uint8 i = 0;
    uint8 step0 = 0;
    uint8 step2 = 0;
    uint8 step3 = 0;

     if (p_sys_fp->l3_rewrite_type == DRV_ENUM(DRV_L3EDITTYPE_RWFLEX))
     {
         SetDsL3EditRwFlex(V, discard_f,            p_ds, 0);
         SetDsL3EditRwFlex(V, discardType_f,        p_ds, 0);
         SetDsL3EditRwFlex(V, nextEditPtrValid_f,   p_ds, 0);
         SetDsL3EditRwFlex(V, outerEditPtr_f,       p_ds, 0);
         SetDsL3EditRwFlex(V, outerEditPtrType_f,   p_ds, 0);
         SetDsL3EditRwFlex(V, l3EditType_f,            p_ds,   p_sys_fp->l3_rewrite_type);
         SetDsL3EditRwFlex(V, aluProfId_f,       p_ds,   p_sys_fp->alu_profile);

         SetDsL3EditRwFlex(A, data_f,            p_ds,   p_sys_fp->raw_data);

         SetDsL3EditRwFlex(V, flexEditTemplateId4_f,       p_ds,   p_sys_fp->template_id4);
         SetDsL3EditRwFlex(V, l3ChksumMaskId_f,            p_ds,   p_sys_fp->l3_chksum_mask_id);
         SetDsL3EditRwFlex(V, l3ChksumSel0_f,       p_ds,   p_sys_fp->l3_chksum_sel);
         SetDsL3EditRwFlex(V, l3ChksumUpdate_f,            p_ds,   p_sys_fp->l3_chksum_update);
         SetDsL3EditRwFlex(V, l4ChksumMaskId_f,       p_ds,   p_sys_fp->l4_chksum_mask_id);
         SetDsL3EditRwFlex(V, l4ChksumSel_f,            p_ds,   p_sys_fp->l4_chksum_sel);
         SetDsL3EditRwFlex(V, l4ChksumUpdate_f,       p_ds,   p_sys_fp->l4_chksum_update);
         SetDsL3EditRwFlex(V, layerId_f,       p_ds,   p_sys_fp->layer_offset_type);
         SetDsL3EditRwFlex(V, layerOffset_f,            p_ds,   p_sys_fp->layer_offset/2); /*2 multiple*/

         SetDsL3EditRwFlex(V, adjustPktL3Length_f,       p_ds,   0);
         SetDsL3EditRwFlex(V, adjustPktL4Length_f,       p_ds,   0);
         SetDsL3EditRwFlex(V, opSegSel_f,       p_ds,   p_sys_fp->op_seg_sel);
         SetDsL3EditRwFlex(V, packetTypeEn_f,       p_ds,   0);
         SetDsL3EditRwFlex(V, packetType_f,       p_ds,   0);
         SetDsL3EditRwFlex(V, rwZoneEn_f,       p_ds,   p_sys_fp->rw_zone);
         SetDsL3EditRwFlex(V, xEditPtr_f,       p_ds,   p_sys_fp->xedit_ptr);

         step0 = DsL3EditRwFlex_f0_1_pos_f - DsL3EditRwFlex_f0_0_pos_f;
         step2 = DsL3EditRwFlex_f2_1_pos_f - DsL3EditRwFlex_f2_0_pos_f;
         step3 = DsL3EditRwFlex_f3_1_pos_f - DsL3EditRwFlex_f3_0_pos_f;

         for (i = 0; i < 4; i++)
         {
             SetDsL3EditRwFlex(V, f0_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[0][i]);
             SetDsL3EditRwFlex(V, f0_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[0][i]);
             SetDsL3EditRwFlex(V, f0_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[0][i]?p_sys_fp->f_sel[0][i]:0x1F);
             SetDsL3EditRwFlex(V, f0_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[0][i]);
             SetDsL3EditRwFlex(V, f0_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[0][i]);

             SetDsL3EditRwFlex(V, f1_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[1][i]);
             SetDsL3EditRwFlex(V, f1_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[1][i]);
             SetDsL3EditRwFlex(V, f1_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[1][i]?p_sys_fp->f_sel[1][i]:0x1F);
             SetDsL3EditRwFlex(V, f1_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[1][i]);
             SetDsL3EditRwFlex(V, f1_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[1][i]);

             SetDsL3EditRwFlex(V, f2_0_maskType_f + i*step2,       p_ds,   p_sys_fp->f_mask[2][i]);
             SetDsL3EditRwFlex(V, f2_0_pos_f + i*step2,       p_ds,   p_sys_fp->f_pos[2][i]);
             SetDsL3EditRwFlex(V, f2_0_sel_f + i*step2,       p_ds,   p_sys_fp->f_valid[2][i]?p_sys_fp->f_sel[2][i]:0x1F);
             SetDsL3EditRwFlex(V, f2_0_zoneId_f + i*step2,       p_ds,   p_sys_fp->f_zone[2][i]);

             SetDsL3EditRwFlex(V, f3_0_pos_f + i*step3,       p_ds,   p_sys_fp->f_pos[3][i]);
             SetDsL3EditRwFlex(V, f3_0_sel_f + i*step3,       p_ds,   p_sys_fp->f_valid[3][i]?p_sys_fp->f_sel[3][i]:0x1F);
             SetDsL3EditRwFlex(V, f3_0_zoneId_f + i*step3,       p_ds,   p_sys_fp->f_zone[3][i]);

         }
     }
     else if(p_sys_fp->l3_rewrite_type == DRV_ENUM(DRV_L3EDITTYPE_INSFLEX) || p_sys_fp->l3_rewrite_type == DRV_ENUM(DRV_L3EDITTYPE_INSFLEX8X))
     {
        if(SYS_NH_FP_INST_PAIR_EXT == p_sys_fp->ext_mode && DRV_FROM_AT(lchip))
        {
            uint8 loop = 0;
            uint32 data_temp = 0;
            for (loop = 0; loop < 12; loop++)
            {
                data_temp = SWAP32(p_sys_fp->raw_data[loop]);

                SetDsL3EditInsFlex0(V, data2_0_f + loop, p_ds, data_temp);
            }
            SetDsL3EditInsFlex0(V, l3EditType0_f, p_ds, p_sys_fp->l3_rewrite_type);
            return CTC_E_NONE;
        }

        SetDsL3EditInsFlex(V, discard_f,            p_ds, 0);
        SetDsL3EditInsFlex(V, discardType_f,        p_ds, 0);
        SetDsL3EditInsFlex(V, nextEditPtrValid_f,   p_ds, 0);
        SetDsL3EditInsFlex(V, outerEditPtr_f,       p_ds, 0);
        SetDsL3EditInsFlex(V, outerEditPtrType_f,   p_ds, 0);
        SetDsL3EditInsFlex(V, l3EditType_f,            p_ds,   p_sys_fp->l3_rewrite_type);
        SetDsL3EditInsFlex(V, aluProfId_f,       p_ds,   p_sys_fp->alu_profile);

        SetDsL3EditInsFlex(V, flexEditTemplateId4_f,       p_ds,   p_sys_fp->template_id4);

        SetDsL3EditInsFlex(V, l3ChksumMaskId_f,            p_ds,   p_sys_fp->l3_chksum_mask_id);
        SetDsL3EditInsFlex(V, l3ChksumSel0_f,       p_ds,   p_sys_fp->l3_chksum_sel);
        SetDsL3EditInsFlex(V, l3ChksumUpdate_f,            p_ds,   p_sys_fp->l3_chksum_update);
        SetDsL3EditInsFlex(V, l3ChksumUpdateX_f,            p_ds,   p_sys_fp->l3_chksum_updatex);

        SetDsL3EditInsFlex(V, l4ChksumMaskId_f,       p_ds,   p_sys_fp->l4_chksum_mask_id);
        SetDsL3EditInsFlex(V, l4ChksumSel_f,            p_ds,   p_sys_fp->l4_chksum_sel);
        SetDsL3EditInsFlex(V, l4ChksumUpdate_f,       p_ds,   p_sys_fp->l4_chksum_update);
        SetDsL3EditInsFlex(V, l4ChksumUpdateX_f,       p_ds,   p_sys_fp->l4_chksum_updatex);

        SetDsL3EditInsFlex(V, layerId_f,       p_ds,   p_sys_fp->layer_offset_type);
        SetDsL3EditInsFlex(V, layerOffset_f,            p_ds,   p_sys_fp->layer_offset/2); /*2 multiple*/

        SetDsL3EditInsFlex(V, layerId0_f,       p_ds,   p_sys_fp->layer_offset_type0);
        SetDsL3EditInsFlex(V, layerOffset0_f,            p_ds,   p_sys_fp->layer_offset0/2); /*2 multiple*/

        SetDsL3EditInsFlex(V, insertHeaderTemplateId_f,       p_ds,   p_sys_fp->ins_profile_id);
        SetDsL3EditInsFlex(V, length_f,       p_ds,   p_sys_fp->ins_del_len/2); /*2 multiple*/

        SetDsL3EditInsFlex(V, rwDataSel_f,       p_ds,  p_sys_fp->rw_data_sel);

        SetDsL3EditInsFlex(V, adjustPktL3Length_f,       p_ds,   p_sys_fp->l3_len_update);
        SetDsL3EditInsFlex(V, adjustPktL4Length_f,       p_ds,   p_sys_fp->l4_len_update);
        SetDsL3EditInsFlex(V, opSegSel_f,       p_ds,   p_sys_fp->op_seg_sel);
        SetDsL3EditInsFlex(V, packetTypeEn_f,       p_ds,   0);
        SetDsL3EditInsFlex(V, packetType_f,       p_ds,   0);
        SetDsL3EditInsFlex(V, rwZoneEn_f,       p_ds,   p_sys_fp->rw_zone);
        SetDsL3EditInsFlex(V, xEditPtr_f,       p_ds,   p_sys_fp->xedit_ptr);

        step0 = DsL3EditInsFlex_f0_1_pos_f - DsL3EditInsFlex_f0_0_pos_f;
        step2 = DsL3EditInsFlex_f2_1_pos_f - DsL3EditInsFlex_f2_0_pos_f;
        step3 = DsL3EditInsFlex_f3_1_pos_f - DsL3EditInsFlex_f3_0_pos_f;

        for (i = 0; i < 4; i++)
        {
            SetDsL3EditInsFlex(V, f0_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[0][i]);
            SetDsL3EditInsFlex(V, f0_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[0][i]);
            SetDsL3EditInsFlex(V, f0_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[0][i]?p_sys_fp->f_sel[0][i]:0x1F);
            SetDsL3EditInsFlex(V, f0_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[0][i]);
            SetDsL3EditInsFlex(V, f0_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[0][i]);

            SetDsL3EditInsFlex(V, f1_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[1][i]);
            SetDsL3EditInsFlex(V, f1_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[1][i]);
            SetDsL3EditInsFlex(V, f1_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[1][i]?p_sys_fp->f_sel[1][i]:0x1F);
            SetDsL3EditInsFlex(V, f1_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[1][i]);
            SetDsL3EditInsFlex(V, f1_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[1][i]);

            SetDsL3EditInsFlex(V, f2_0_maskType_f + i*step2,       p_ds,   p_sys_fp->f_mask[2][i]);
            SetDsL3EditInsFlex(V, f2_0_pos_f + i*step2,       p_ds,   p_sys_fp->f_pos[2][i]);
            SetDsL3EditInsFlex(V, f2_0_sel_f + i*step2,       p_ds,   p_sys_fp->f_valid[2][i]?p_sys_fp->f_sel[2][i]:0x1F);
            SetDsL3EditInsFlex(V, f2_0_zoneId_f + i*step2,       p_ds,   p_sys_fp->f_zone[2][i]);

            SetDsL3EditInsFlex(V, f3_0_pos_f + i*step3,       p_ds,   p_sys_fp->f_pos[3][i]);
            SetDsL3EditInsFlex(V, f3_0_sel_f + i*step3,       p_ds,   p_sys_fp->f_valid[3][i]?p_sys_fp->f_sel[3][i]:0x1F);
            SetDsL3EditInsFlex(V, f3_0_zoneId_f + i*step3,       p_ds,   p_sys_fp->f_zone[3][i]);

        }


        if (p_sys_fp->ext_mode)
        {
            SetDsL3EditInsFlex(A, data1_f,            p_ds,   p_sys_fp->raw_data);
        }
        else
        {
            SetDsL3EditInsFlex(A, data_f,            p_ds,   p_sys_fp->raw_data);
        }

     }
     else if(p_sys_fp->l3_rewrite_type == DRV_ENUM(DRV_L3EDITTYPE_DELFLEX))
     {
         SetDsL3EditDelFlex(V, discard_f,            p_ds, 0);
         SetDsL3EditDelFlex(V, discardType_f,        p_ds, 0);
         SetDsL3EditDelFlex(V, nextEditPtrValid_f,   p_ds, 0);
         SetDsL3EditDelFlex(V, outerEditPtr_f,       p_ds, 0);
         SetDsL3EditDelFlex(V, outerEditPtrType_f,   p_ds, 0);
         SetDsL3EditDelFlex(V, l3EditType_f,            p_ds,   p_sys_fp->l3_rewrite_type);
         SetDsL3EditDelFlex(V, aluProfId_f,       p_ds,   p_sys_fp->alu_profile);

         SetDsL3EditDelFlex(V, flexEditTemplateId4_f,       p_ds,   p_sys_fp->template_id4);

         SetDsL3EditDelFlex(V, l3ChksumMaskId_f,            p_ds,   p_sys_fp->l3_chksum_mask_id);
         SetDsL3EditDelFlex(V, l3ChksumSel0_f,       p_ds,   p_sys_fp->l3_chksum_sel);
         SetDsL3EditDelFlex(V, l3ChksumUpdate_f,            p_ds,   p_sys_fp->l3_chksum_update);
         SetDsL3EditDelFlex(V, l3ChksumUpdateX_f,            p_ds,   p_sys_fp->l3_chksum_updatex);

         SetDsL3EditDelFlex(V, l4ChksumMaskId_f,       p_ds,   p_sys_fp->l4_chksum_mask_id);
         SetDsL3EditDelFlex(V, l4ChksumSel_f,            p_ds,   p_sys_fp->l4_chksum_sel);
         SetDsL3EditDelFlex(V, l4ChksumUpdate_f,       p_ds,   p_sys_fp->l4_chksum_update);
         SetDsL3EditDelFlex(V, l4ChksumUpdateX_f,       p_ds,   p_sys_fp->l4_chksum_updatex);

         SetDsL3EditDelFlex(V, layerId_f,       p_ds,   p_sys_fp->layer_offset_type);
         SetDsL3EditDelFlex(V, layerOffset_f,            p_ds,   p_sys_fp->layer_offset/2); /*2 multiple*/

         SetDsL3EditDelFlex(V, layerId0_f,       p_ds,   p_sys_fp->layer_offset_type0);
         SetDsL3EditDelFlex(V, layerOffset0_f,            p_ds,   p_sys_fp->layer_offset0/2); /*2 multiple*/

         if (p_sys_fp->len_from_data)
         {
             SetDsL3EditDelFlex(V, lengthFromContainerEn_f,       p_ds,   1);
             SetDsL3EditDelFlex(V, length_f,       p_ds,   p_sys_fp->ins_del_len); /*sel*/
         }
         else
         {
             SetDsL3EditDelFlex(V, lengthFromContainerEn_f,       p_ds,   0);
             SetDsL3EditDelFlex(V, length_f,       p_ds,   p_sys_fp->ins_del_len / 2); /*2 multiple*/
         }

         SetDsL3EditDelFlex(V, adjustPktL3Length_f,       p_ds,   p_sys_fp->l3_len_update);
         SetDsL3EditDelFlex(V, adjustPktL4Length_f,       p_ds,   p_sys_fp->l4_len_update);
         SetDsL3EditDelFlex(V, opSegSel_f,       p_ds,   p_sys_fp->op_seg_sel);
         SetDsL3EditDelFlex(V, packetTypeEn_f,       p_ds,   0);
         SetDsL3EditDelFlex(V, packetType_f,       p_ds,   0);
         SetDsL3EditDelFlex(V, rwZoneEn_f,       p_ds,   p_sys_fp->rw_zone);
         SetDsL3EditDelFlex(V, xEditPtr_f,       p_ds,   p_sys_fp->xedit_ptr);

         step0 = DsL3EditDelFlex_f0_1_pos_f - DsL3EditDelFlex_f0_0_pos_f;
         step2 = DsL3EditDelFlex_f2_1_pos_f - DsL3EditDelFlex_f2_0_pos_f;
         step3 = DsL3EditDelFlex_f3_1_pos_f - DsL3EditDelFlex_f3_0_pos_f;

         for (i = 0; i < 4; i++)
         {
             SetDsL3EditDelFlex(V, f0_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[0][i]);
             SetDsL3EditDelFlex(V, f0_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[0][i]);
             SetDsL3EditDelFlex(V, f0_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[0][i]?p_sys_fp->f_sel[0][i]:0x1F);
             SetDsL3EditDelFlex(V, f0_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[0][i]);
             SetDsL3EditDelFlex(V, f0_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[0][i]);

             SetDsL3EditDelFlex(V, f1_0_mask_f + i*step0,       p_ds,   p_sys_fp->f_mask[1][i]);
             SetDsL3EditDelFlex(V, f1_0_pos_f + i*step0,       p_ds,   p_sys_fp->f_pos[1][i]);
             SetDsL3EditDelFlex(V, f1_0_sel_f + i*step0,       p_ds,   p_sys_fp->f_valid[1][i]?p_sys_fp->f_sel[1][i]:0x1F);
             SetDsL3EditDelFlex(V, f1_0_shift_f + i*step0,       p_ds,   p_sys_fp->f_shift[1][i]);
             SetDsL3EditDelFlex(V, f1_0_zoneId_f + i*step0,       p_ds,   p_sys_fp->f_zone[1][i]);

             SetDsL3EditDelFlex(V, f2_0_maskType_f + i*step2,       p_ds,   p_sys_fp->f_mask[2][i]);
             SetDsL3EditDelFlex(V, f2_0_pos_f + i*step2,       p_ds,   p_sys_fp->f_pos[2][i]);
             SetDsL3EditDelFlex(V, f2_0_sel_f + i*step2,       p_ds,   p_sys_fp->f_valid[2][i]?p_sys_fp->f_sel[2][i]:0x1F);
             SetDsL3EditDelFlex(V, f2_0_zoneId_f + i*step2,       p_ds,   p_sys_fp->f_zone[2][i]);

             SetDsL3EditDelFlex(V, f3_0_pos_f + i*step3,       p_ds,   p_sys_fp->f_pos[3][i]);
             SetDsL3EditDelFlex(V, f3_0_sel_f + i*step3,       p_ds,   p_sys_fp->f_valid[3][i]?p_sys_fp->f_sel[3][i]:0x1F);
             SetDsL3EditDelFlex(V, f3_0_zoneId_f + i*step3,       p_ds,   p_sys_fp->f_zone[3][i]);

         }

         if (p_sys_fp->ext_mode)
         {
             SetDsL3EditDelFlex(A, data1_f,            p_ds,   p_sys_fp->raw_data);
         }
         else
         {
             SetDsL3EditDelFlex(A, data_f,            p_ds,   p_sys_fp->raw_data);
         }

     }
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_logic_dest_port(uint8 lchip, sys_ldp_t* p_sys_ldp, void *p_ds, uint32* p_offset)
{
    if (DRV_ENUM(DRV_EGRESSSCLHASHTYPE_VPPAIR) == p_sys_ldp->scl1_hash_type && (SYS_INVALID_ISOLATION_ID != p_sys_ldp->isolation_id) && (0 != p_sys_ldp->isolation_id))
    {
        return CTC_E_INVALID_PARAM;
    }
    else if((SYS_INVALID_ISOLATION_ID != p_sys_ldp->isolation_id) && (0 != p_sys_ldp->isolation_id))
    {/* for DCI, metadata + isolation_id(located in lp_grp_id)*/
        SetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds, (1<< 15)| (p_sys_ldp->isolation_id <<10) | p_sys_ldp->lp_grp_id);
	    SetDsEgressLogicDestPort(V, logicPortIsolateEn_f, p_ds,1);
	}
    else
    {/* for AC isolation, cid + lp_grp_id)*/
        SetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds, p_sys_ldp->lp_grp_id);
        SetDsEgressLogicDestPort(V, logicPortIsolateEn_f, p_ds,0);
    }
    SetDsEgressLogicDestPort(V, destVlanPtr_f, p_ds, p_sys_ldp->dest_vlan_ptr);

    if (p_sys_ldp->l3edit_ptr)
    {
        SetDsEgressLogicDestPort(V, outerEditLocation_f, p_ds, 0);
        SetDsEgressLogicDestPort(V, outerEditPtrType_f, p_ds, 1);
        SetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds, p_sys_ldp->l3edit_ptr);
        SetDsEgressLogicDestPort(V, editPtrMode_f, p_ds, p_sys_ldp->edit_mode);
    }
    else if(p_sys_ldp->l2edit_ptr)
    {
        SetDsEgressLogicDestPort(V, outerEditLocation_f, p_ds, 0);
        SetDsEgressLogicDestPort(V, outerEditPtrType_f, p_ds, 0);
        SetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds, p_sys_ldp->l2edit_ptr);
        SetDsEgressLogicDestPort(V, editPtrMode_f, p_ds, 2);
    }
    else if (p_sys_ldp->stats_ptr)
    {
        SetDsEgressLogicDestPort(V, outerEditLocation_f, p_ds, 0);
        SetDsEgressLogicDestPort(V, outerEditPtrType_f, p_ds, 0);
        SetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds, p_sys_ldp->stats_ptr);
        SetDsEgressLogicDestPort(V, editPtrMode_f, p_ds, 4);
    }

    SetDsEgressLogicDestPort(V, scl0HashType_f, p_ds, p_sys_ldp->scl0_hash_type);
    SetDsEgressLogicDestPort(V, scl1HashType_f, p_ds, p_sys_ldp->scl1_hash_type);

    SetDsEgressLogicDestPort(V, macDaProfileId_f, p_ds, p_sys_ldp->l2edit_ptr);

    if (p_sys_ldp->esid)
    {
        SetDsEgressLogicDestPort(V, dvpGidShareModeForMplsEvpn_f, p_ds, 1);
        SetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds, p_sys_ldp->esid<<8|(p_sys_ldp->lp_grp_id&0xFF));
    }
    else
    {
        SetDsEgressLogicDestPort(V, dvpGidShareModeForMplsEvpn_f, p_ds, 0);
    }

    SetDsEgressLogicDestPort(V, aclKeyMergeInnerAndOuterHdrValid_f, p_ds, p_sys_ldp->acl_merge_valid);
    SetDsEgressLogicDestPort(V, aclKeyMergeInnerAndOuterHdr_f, p_ds, p_sys_ldp->acl_merge);
    SetDsEgressLogicDestPort(V, aclQosUseOuterInfoValid_f, p_ds, p_sys_ldp->acl_use_outer_valid);
    SetDsEgressLogicDestPort(V, aclQosUseOuterInfo_f, p_ds, p_sys_ldp->acl_use_outer);
    SetDsEgressLogicDestPort(V, ipfixUseOuterInfoValid_f, p_ds, p_sys_ldp->ipfix_use_outer_valid);
    SetDsEgressLogicDestPort(V, ipfixUseOuterInfo_f, p_ds, p_sys_ldp->ipfix_use_outer);

    if (p_sys_ldp->nsh_en)
    {
        drv_ftm_info_detail_t ftm_info;
        ftm_info.info_type = DRV_FTM_INFO_TYPE_MAX;
        CTC_ERROR_RETURN(drv_usw_ftm_get_info_detail(lchip, &ftm_info));
        if (ftm_info.nsh_mode & 1)
        {
            SetDsEgressLogicDestPort(V, scl1XkeyEn_f, p_ds, 1);
            SetDsEgressLogicDestPort(V, scl1HashType_f, p_ds, SYS_PORT_EGR_SCL_HASH_TYPE_NSH);
        }
        else
        {
            SetDsEgressLogicDestPort(V, scl0XkeyEn_f, p_ds, 1);
            SetDsEgressLogicDestPort(V, scl0HashType_f, p_ds, SYS_PORT_EGR_SCL_HASH_TYPE_NSH);
        }
    }

    return CTC_E_NONE;
}
int32
sys_usw_nh_unmap_logic_dest_port(uint8 lchip, sys_ldp_t* p_sys_ldp, void *p_ds, uint32* p_offset)
{
    p_sys_ldp->dest_vlan_ptr = GetDsEgressLogicDestPort(V, destVlanPtr_f, p_ds);

    p_sys_ldp->scl0_hash_type = GetDsEgressLogicDestPort(V, scl0HashType_f, p_ds);
    p_sys_ldp->scl1_hash_type = GetDsEgressLogicDestPort(V, scl1HashType_f, p_ds);

    if (4 == GetDsEgressLogicDestPort(V, editPtrMode_f, p_ds))
    {
        p_sys_ldp->stats_ptr = GetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds);
    }
    else if (2 == GetDsEgressLogicDestPort(V, editPtrMode_f, p_ds))
    {
        p_sys_ldp->l2edit_ptr = GetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds);
    }
    else if (0 == GetDsEgressLogicDestPort(V, editPtrMode_f, p_ds))
    {
        p_sys_ldp->l3edit_ptr = GetDsEgressLogicDestPort(V, outerEditPtr_f, p_ds);
    }

    if(p_sys_ldp->scl1_hash_type == DRV_ENUM(DRV_EGRESSSCLHASHTYPE_VPPAIR))
    {
        p_sys_ldp->isolation_id = SYS_INVALID_ISOLATION_ID;
    }
    else if((p_sys_ldp->scl1_hash_type == DRV_ENUM(DRV_EGRESSSCLHASHTYPE_METADATADVPGROUP))
        || (1 == GetDsEgressLogicDestPort(V, logicPortIsolateEn_f, p_ds))
        || (1 == ((GetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds) >> 15) & 0x1)))
    {
        p_sys_ldp->isolation_id = (GetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds) >> 10)& SYS_ISOLATION_ID_MAX;
    }
    else
    {
        p_sys_ldp->isolation_id = 0;
    }

    p_sys_ldp->lp_grp_id = GetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds) & SYS_LP_GRP_ID_MAX;
    if (1 == GetDsEgressLogicDestPort(V, dvpGidShareModeForMplsEvpn_f, p_ds))
    {
        p_sys_ldp->esid = (GetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds)>>8) & 0xFF;
        p_sys_ldp->lp_grp_id = GetDsEgressLogicDestPort(V, logicDestPortGid_f, p_ds) & 0xFF;
    }
    p_sys_ldp->acl_merge_valid = GetDsEgressLogicDestPort(V, aclKeyMergeInnerAndOuterHdrValid_f, p_ds);
    p_sys_ldp->acl_merge = GetDsEgressLogicDestPort(V, aclKeyMergeInnerAndOuterHdr_f, p_ds);
    p_sys_ldp->acl_use_outer_valid = GetDsEgressLogicDestPort(V, aclQosUseOuterInfoValid_f, p_ds);
    p_sys_ldp->acl_use_outer = GetDsEgressLogicDestPort(V, aclQosUseOuterInfo_f, p_ds);
    p_sys_ldp->ipfix_use_outer_valid = GetDsEgressLogicDestPort(V, ipfixUseOuterInfoValid_f, p_ds);
    p_sys_ldp->ipfix_use_outer = GetDsEgressLogicDestPort(V, ipfixUseOuterInfo_f, p_ds);

    if (GetDsEgressLogicDestPort(V, scl1XkeyEn_f, p_ds) || GetDsEgressLogicDestPort(V, scl0XkeyEn_f, p_ds))
    {
        p_sys_ldp->nsh_en = 1;
    }
    return CTC_E_NONE;
}

#define FROM_TMM_END

#define FROM_AT_START

int32
sys_usw_nh_map_met(uint8 lchip, sys_met_t* p_sys_met, void *p_ds, uint32* p_offset)
{
#if defined(ARCTIC)
    if (p_sys_met->mcast_mode)/*bmp mode*/
    {
        SetDsMetVector1X(V, nextMetEntryPtr_f,      p_ds,      p_sys_met->next_met_entry_ptr);
        SetDsMetVector1X(V, endLocalRep_f,          p_ds,      p_sys_met->end_local_rep);
        SetDsMetVector1X(V, isLinkAggregation_f,    p_ds,      p_sys_met->is_agg);
        SetDsMetVector1X(V, phyPortCheckDiscard_f,  p_ds,      p_sys_met->phy_port_chk_discard);
        if (p_sys_met->next_hop_ptr)
        {
            SetDsMetVector1X(V, replicationCtl_f,   p_ds,     (1 << 18) | p_sys_met->next_hop_ptr);
        }
        if (p_sys_met->is_12w)
        {
            SetDsMetVector4X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYTYPE_PORTBMP4X));
            SetDsMetVector4X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));/*96bits*/
            SetDsMetVector4X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[3]));/*128bits*/
            SetDsMetVector4X(A, portBitmap2_f,      p_ds,      &(p_sys_met->port_bitmap[7]));/*288bits*/
        }
        else if (p_sys_met->is_6w)
        {
            SetDsMetVector2X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYTYPE_PORTBMP2X));
            SetDsMetVector2X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base]));/*96bits*/
            SetDsMetVector2X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base + 3]));/*128bits*/
            ((uint32*)p_ds)[9] |= (p_sys_met->port_bitmap_base << 8);
        }
        else
        {
            SetDsMetVector1X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYTYPE_PORTBMP1X));
            SetDsMetVector1X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base]));/*96bits*/
            ((uint32*)p_ds)[4] |= (p_sys_met->port_bitmap_base << 8);
        }
    }
    else
    {
        SetDsMetEntry1X(V, metEntryType_f,          p_ds,      DRV_ENUM(DRV_METENTRYTYPE_LINKLIST));
        SetDsMetEntry1X(V, nextMetEntryPtr_f,       p_ds,      p_sys_met->next_met_entry_ptr);
        SetDsMetEntry1X(V, endLocalRep_f,           p_ds,      p_sys_met->end_local_rep);
        SetDsMetEntry1X(V, isLinkAggregation_f,     p_ds,      p_sys_met->is_agg);
        SetDsMetEntry1X(V, phyPortCheckDiscard_f,   p_ds,      p_sys_met->phy_port_chk_discard);
        SetDsMetEntry1X(V, remoteChip_f,            p_ds,      p_sys_met->remote_chip);
        SetDsMetEntry1X(V, leafCheckEn_f,           p_ds,      p_sys_met->leaf_check_en);
        SetDsMetEntry1X(V, logicPortTypeCheck_f,    p_ds,      p_sys_met->logic_port_type_check);
        SetDsMetEntry1X(V, apsBridgeEn_f,           p_ds,      p_sys_met->aps_bridge_en);
        SetDsMetEntry1X(V, ucastId_f,               p_ds,      p_sys_met->dest_id);
        SetDsMetEntry1X(V, forceBackEn_f,           p_ds,      p_sys_met->force_back_en);
        SetDsMetEntry1X(V, replicationCtl_f,    p_ds,     (1 << 18) | p_sys_met->next_hop_ptr);

        if (p_sys_met->fid)
        {
            SetDsMetEntry1X(V, fidValid_f,          p_ds,   1);
            SetDsMetEntry1X(V, logicDestPort_f,     p_ds,      p_sys_met->fid);
        }
        else
        {
            SetDsMetEntry1X(V, logicDestPort_f,     p_ds,      p_sys_met->logic_dest_port);
            SetDsMetEntry1X(V, logicPortCheckEn_f,  p_ds,      p_sys_met->logic_port_check_en);
        }
        if(p_sys_met->ldp_ext)
        {
            SetDsMetEntry1X(V, auxData_f,  p_ds,      p_sys_met->ldp_ext);
            SetDsMetEntry1X(V, xHeaderExtType_f,  p_ds,      1);
        }
    }
#endif
    return CTC_E_NONE;
}
int32
sys_usw_nh_unmap_met(uint8 lchip, sys_met_t* p_sys_met, void *p_ds)
{
#if defined(ARCTIC)
    uint32 metEntryType = GetDsMetEntry1X(V, metEntryType_f, p_ds);
    if (DRV_ENUM(DRV_METENTRYTYPE_PORTBMP1X) == metEntryType)
    {
        p_sys_met->port_bitmap_base = (((uint32*)p_ds)[4] >> 8) & 0x3;
        GetDsMetVector1X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base]));/*96bits*/
    }
    else if (DRV_ENUM(DRV_METENTRYTYPE_PORTBMP2X) == metEntryType)
    {
        p_sys_met->port_bitmap_base = (((uint32*)p_ds)[9] >> 8) & 0x3;
        GetDsMetVector2X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base]));/*96bits*/
        GetDsMetVector2X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[3*p_sys_met->port_bitmap_base + 3]));/*128bits*/
    }
    else if (DRV_ENUM(DRV_METENTRYTYPE_PORTBMP4X) == metEntryType)
    {
        GetDsMetVector4X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));/*96bits*/
        GetDsMetVector4X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[3]));/*128bits*/
        GetDsMetVector4X(A, portBitmap2_f,      p_ds,      &(p_sys_met->port_bitmap[7]));/*288bits*/
    }

    if(GetDsMetEntry1X(V, xHeaderExtType_f,  p_ds) == 1)
    {
        p_sys_met->ldp_ext = GetDsMetEntry1X(V, auxData_f,  p_ds);

    }

#endif
    return CTC_E_NONE;
}


int32
sys_usw_nh_map_metslim(uint8 lchip, sys_met_t* p_sys_met, void *p_ds, uint32* p_offset)
{
#if defined(ARCTIC)
    if (p_sys_met->mcast_mode)/*bmp*/
    {
        SetDsMetVectorSlim1X(V, nextMetEntryPtr_f,      p_ds,      p_sys_met->next_met_entry_ptr);
        SetDsMetVectorSlim1X(V, isLinkAggregation_f,    p_ds,      p_sys_met->is_agg);
        if (p_sys_met->next_hop_ptr)
        {
            SetDsMetVectorSlim2X(V, replicationCtl_f,   p_ds,      (1 << 18) | p_sys_met->next_hop_ptr);
            SetDsMetVectorSlim2X(V, replicationCtlEn_f, p_ds,      1);
        }
        SetDsMetVectorSlim2X(V, endLocalRep_f,          p_ds,      p_sys_met->end_local_rep);
        SetDsMetVectorSlim2X(V, phyPortCheckDiscard_f,  p_ds,      p_sys_met->phy_port_chk_discard);

        if (p_sys_met->is_12w)
        {
            SetDsMetVectorSlim4X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP4X));
            SetDsMetVectorSlim4X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));
            SetDsMetVectorSlim4X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[2]));
            SetDsMetVectorSlim4X(A, portBitmap2_f,      p_ds,      &(p_sys_met->port_bitmap[4]));
            ((uint32*)p_ds)[11] = (p_sys_met->port_bitmap_base << 22);
        }
        else if (p_sys_met->is_6w)
        {
            SetDsMetVectorSlim2X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP2X));
            SetDsMetVectorSlim2X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));/*64bits*/
            SetDsMetVectorSlim2X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[2]));/*64bits*/
            ((uint32*)p_ds)[5] |= (p_sys_met->port_bitmap_base << 22);
        }
        else
        {
            SetDsMetVectorSlim1X(V, metEntryType_f,     p_ds,      DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP1X));
            SetDsMetVectorSlim1X(A, portBitmap0_f,      p_ds,      p_sys_met->port_bitmap);/*64bits*/
        }
    }
    else
    {
        SetDsMetEntrySlim1X(V, metEntryType_f,          p_ds,      DRV_ENUM(DRV_METENTRYSLIMTYPE_LINKLIST));
        SetDsMetEntrySlim1X(V, nextMetEntryPtr_f,       p_ds,      p_sys_met->next_met_entry_ptr);
        SetDsMetEntrySlim1X(V, endLocalRep_f,           p_ds,      p_sys_met->end_local_rep);
        SetDsMetEntrySlim1X(V, isLinkAggregation_f,     p_ds,      p_sys_met->is_agg);
        SetDsMetEntrySlim1X(V, phyPortCheckDiscard_f,   p_ds,      p_sys_met->phy_port_chk_discard);
        SetDsMetEntrySlim1X(V, remoteChip_f,            p_ds,      p_sys_met->remote_chip);
        SetDsMetEntrySlim1X(V, leafCheckEn_f,           p_ds,      p_sys_met->leaf_check_en);
        SetDsMetEntrySlim1X(V, logicPortTypeCheck_f,    p_ds,      p_sys_met->logic_port_type_check);
        SetDsMetEntrySlim1X(V, apsBridgeEn_f,           p_ds,      p_sys_met->aps_bridge_en);
        SetDsMetEntrySlim1X(V, ucastId_f,               p_ds,      p_sys_met->dest_id);
        SetDsMetEntrySlim1X(V, forceBackEn_f,           p_ds,      p_sys_met->force_back_en);
        SetDsMetEntrySlim1X(V, replicationCtl_f,        p_ds,      (1 << 18) | p_sys_met->next_hop_ptr);

        if (p_sys_met->fid)
        {
            SetDsMetEntrySlim1X(V, fidValid_f,          p_ds,   1);
            SetDsMetEntrySlim1X(V, logicDestPort_f,     p_ds,      p_sys_met->fid);
        }
        else
        {
            SetDsMetEntrySlim1X(V, logicDestPort_f,     p_ds,      p_sys_met->logic_dest_port);
            SetDsMetEntrySlim1X(V, logicPortCheckEn_f,  p_ds,      p_sys_met->logic_port_check_en);
        }
    }
#endif
    return CTC_E_NONE;
}

int32
sys_usw_nh_unmap_metslim(uint8 lchip, sys_met_t* p_sys_met, void *p_ds)
{
#if defined(ARCTIC)
        uint32 metEntryType = GetDsMetVectorSlim1X(V, metEntryType_f, p_ds);
        if (DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP1X) == metEntryType)
        {
            GetDsMetVectorSlim1X(A, portBitmap0_f,      p_ds,      p_sys_met->port_bitmap);/*64bits*/
        }
        else if (DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP2X) == metEntryType)
        {
            GetDsMetVectorSlim2X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));/*64bits*/
            GetDsMetVectorSlim2X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[2]));/*64bits*/
        }
        else if (DRV_ENUM(DRV_METENTRYSLIMTYPE_PORTBMP4X) == metEntryType)
        {
            GetDsMetVectorSlim4X(A, portBitmap0_f,      p_ds,      &(p_sys_met->port_bitmap[0]));
            GetDsMetVectorSlim4X(A, portBitmap1_f,      p_ds,      &(p_sys_met->port_bitmap[2]));
            GetDsMetVectorSlim4X(A, portBitmap2_f,      p_ds,      &(p_sys_met->port_bitmap[4]));
        }
#endif

    return CTC_E_NONE;
}


int32
sys_usw_nh_table_info_init_inner(uint8 lchip)
{
#if defined(ARCTIC)
    uint8 idx = 0;
    uint8 idx1 = 0;
    uint8 step = SYS_NH_TYPE_STEP_TO_INNER;
    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

     #define SYS_TBL_INFO_FUNC(idx) p_nh_master->nh_table_info_array[idx].p_func
     #define SYS_TBL_INFO_FUNC_UNMAP(idx) p_nh_master->nh_table_info_array[idx].p_func_unmap
     #define SYS_TBL_INFO_FUNC_UPDATE(idx) p_nh_master->nh_table_info_array[idx].p_update
     #define SYS_TBL_INFO_ID(idx) p_nh_master->nh_table_info_array[idx].table_id
     #define SYS_TBL_INFO_OPF_DIR(idx) p_nh_master->nh_table_info_array[idx].alloc_dir

    for (idx = SYS_NH_ENTRY_TYPE_L2EDIT_FROM; idx <= SYS_NH_ENTRY_TYPE_L3EDIT_TO; idx++)
    {
        idx1 = idx + step;
        switch(idx)
        {
        /* +++ share edit memory start+++ */
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddMpls1X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_addmpls;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS_2X:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddMpls2X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addmpls_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS_12W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddMpls4X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addmpls_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditAddEth1X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l2edit_addeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l2edit_addeth;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditAddEth2X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l2edit_addeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l2edit_addeth;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditRwEth1X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_inner_autoeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l2edit_inner_autoeth;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W_RW:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditRwEth2X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_inner_autoeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l2edit_inner_autoeth;
            break;

        case SYS_NH_ENTRY_TYPE_L2EDIT_FLEX_8W:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditGemPort0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_gemport;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_SWAP:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditRwEth1X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_inner_swap;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsl2edit_inner_swap;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_SWAP:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditRwEth2X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_rweth2x;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_OF_6W:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditRwEth2X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_rweth2x;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_LPBK:
            SYS_TBL_INFO_ID(idx1)   = DsL2EditLoopback0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_loopback;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V4:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddIp40_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_addip4;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_addip4;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V4_4X:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddIp44X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addip4;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addip4;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V6:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddIp60_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_addip6;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_addip6;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_4W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp41X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip41x_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip41x_nat;
            SYS_TBL_INFO_OPF_DIR(idx1) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_8W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp40_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip4_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip4_nat;
            SYS_TBL_INFO_OPF_DIR(idx1) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_V6_8W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp62X0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip6_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip6_nat;
            SYS_TBL_INFO_OPF_DIR(idx1) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_V6_16W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp60_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip6_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip6_nat;
            SYS_TBL_INFO_OPF_DIR(idx1) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_ADD_SRV6:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddIp6Sr_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addip6_sr;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addip6_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_RW_SRV6:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp6Sr_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip6_sr;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_rwip6_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_SRH:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddIp6ExtHeader_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_srh;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_OF_6W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp40_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip4;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_OF_12W:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwIp60_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip6;
            break;
       case SYS_NH_ENTRY_TYPE_L3EDIT_TRILL:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddTrill0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_trill;
            break;
       case SYS_NH_ENTRY_TYPE_L3EDIT_LPBK:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditLoopback0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_dsl3edit_loopback;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_ADD_RAW:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditAddRaw0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addraw;
            SYS_TBL_INFO_FUNC_UNMAP(idx1) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addraw;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_FP:
            SYS_TBL_INFO_ID(idx1)   = DsL3EditRwFlex0_t;
            SYS_TBL_INFO_FUNC(idx1) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_fp;
            break;
        default:
            break;

        }
    }
#endif
    return CTC_E_NONE;
}

#define FROM_AT_END
int32
sys_usw_nh_write_asic_table(uint8 lchip,
                                  uint8 table_type, uint32 offset, void* value)
{
    uint32 cmd    = 0;
    uint32 tbl_id = 0;
    void *p_ds = value;
    ds0_t ds;
    ds0_t ds1;
    uint32 spme_offset = offset;

    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

    if (p_nh_master->nh_table_info_array[table_type].p_func)
    {
        sal_memset(ds, 0, sizeof(ds));
        CTC_ERROR_RETURN((*p_nh_master->nh_table_info_array[table_type].p_func)(lchip, value, &ds, &offset));
        p_ds = (void*)ds;
        if (SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W == table_type)
        {
            uint8 len = DRV_TABLE_ENTRY_SIZE(lchip, DsL2Edit6WOuter_t) / 2;
            CTC_ERROR_RETURN(sys_usw_nh_get_asic_table(lchip, SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W, offset, &ds1));
            if (offset % 2 == 0)
            {
                sal_memcpy((uint8*)&ds1, &ds, len);
            }
            else
            {
                sal_memcpy((uint8*)&ds1 + len, &ds, len);
            }
            p_ds = (void*)ds1;
            offset = offset / 2;
        }
        else if(SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W == table_type)
        {
            offset = offset / 2;
        }
    }

    tbl_id = p_nh_master->nh_table_info_array[table_type].table_id;

    if ((table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W || table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W) &&
        (spme_offset >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        tbl_id = DsL3Edit6W3rd_t;
        offset = (spme_offset - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM))/2;
    }

    cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, offset, cmd, p_ds));

    return CTC_E_NONE;
}

int32
sys_usw_nh_read_asic_table(uint8 lchip,
                                  uint8 table_type, uint32 offset, void* value)
{
    uint32 cmd    = 0;
    uint32 tbl_id = 0;
    ds0_t ds;
    uint32 offset_tmp = offset;
    uint8 real_type = table_type;

    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

    if ((table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W || table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W) &&
        (offset >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        table_type = SYS_NH_ENTRY_TYPE_L3EDIT_SPME;
        offset = offset - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM);
    }

    if (SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W == table_type || SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W == table_type ||
        SYS_NH_ENTRY_TYPE_L3EDIT_SPME == table_type || SYS_NH_ENTRY_TYPE_FWD_HALF == table_type ||
        SYS_NH_ENTRY_TYPE_FWD_HALF1 == table_type)
    {
        offset_tmp = offset / 2;
    }

    sal_memset(ds, 0, sizeof(ds));
    tbl_id = p_nh_master->nh_table_info_array[table_type].table_id;
    cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
    if (DRV_E_NONE != DRV_IOCTL(lchip, offset_tmp, cmd, ds))
    {
        SYS_NH_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " [ASIC] Hardware operation failed \n");
        return CTC_E_HW_FAIL;
    }
    if (SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W == real_type)
    {
        uint8 len = DRV_TABLE_ENTRY_SIZE(lchip, DsL2Edit6WOuter_t) / 2;
        if(CTC_IS_BIT_SET(offset, 0))
        {
            sal_memcpy((uint8*)&ds, (uint8*)&ds + len, len);
        }
        sal_memset((uint8*)&ds + len, 0, len);
    }

    if (p_nh_master->nh_table_info_array[real_type].p_func_unmap)
    {
        CTC_ERROR_RETURN((*p_nh_master->nh_table_info_array[real_type].p_func_unmap)(lchip, value, &ds));
    }

    return CTC_E_NONE;
}

int32
sys_usw_nh_update_asic_table(uint8 lchip,
                                   uint8 table_type, uint32 offset, void* value)
{

    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

    if (p_nh_master->nh_table_info_array[table_type].p_update)
    {
        (*p_nh_master->nh_table_info_array[table_type].p_update)(lchip, value);
    }

    return CTC_E_NONE;
}



int32
sys_usw_nh_get_asic_table(uint8 lchip,
                                uint8 table_type, uint32 offset, void* value)
{
    uint32 cmd;
    uint32 tbl_id;
    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

    if ((table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W || table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W) &&
        (offset >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        table_type = SYS_NH_ENTRY_TYPE_L3EDIT_SPME;
        offset = offset - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM);
    }
    switch(table_type)
    {
    case SYS_NH_ENTRY_TYPE_FWD:
    case SYS_NH_ENTRY_TYPE_FWD1:
    case SYS_NH_ENTRY_TYPE_L3EDIT_SPME:
    case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W:
    case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W:
        offset = offset / 2;
        break;

    default:
        break;
    }

    tbl_id = p_nh_master->nh_table_info_array[table_type].table_id;
    cmd = DRV_IOR(tbl_id, DRV_ENTRY_FLAG);
    if (DRV_E_NONE != DRV_IOCTL(lchip, offset, cmd, value))
    {
        SYS_NH_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " [ASIC] Hardware operation failed \n");
        return CTC_E_HW_FAIL;
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_set_asic_table(uint8 lchip,
                                uint8 table_type, uint32 offset, void* value)
{
    uint32 cmd;
    uint32 tbl_id;
    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

    if ((table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W || table_type == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W) &&
        (offset >= MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM)))
    {
        table_type = SYS_NH_ENTRY_TYPE_L3EDIT_SPME;
        offset = offset - MCHIP_CAP(SYS_CAP_NH_OUTER_L2_EDIT_NUM);
    }

    switch (table_type)
    {
    case SYS_NH_ENTRY_TYPE_FWD:
    case SYS_NH_ENTRY_TYPE_FWD1:
    case SYS_NH_ENTRY_TYPE_L3EDIT_SPME:
    case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W:
    case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W:
        offset = offset / 2;
        break;
    default:
        break;
    }

    tbl_id = p_nh_master->nh_table_info_array[table_type].table_id;
    cmd = DRV_IOW(tbl_id, DRV_ENTRY_FLAG);

    if (DRV_E_NONE != DRV_IOCTL(lchip, offset, cmd, value))
    {
        SYS_NH_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " [ASIC] Hardware operation failed \n");
        return CTC_E_HW_FAIL;
    }

    return CTC_E_NONE;

}


int32
sys_usw_nh_table_info_init(uint8 lchip)
{
    uint8 idx = 0;
    uint32 entry_size = 0;
    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];

     #define SYS_TBL_INFO_FUNC(idx) p_nh_master->nh_table_info_array[idx].p_func
     #define SYS_TBL_INFO_FUNC_UNMAP(idx) p_nh_master->nh_table_info_array[idx].p_func_unmap
     #define SYS_TBL_INFO_FUNC_UPDATE(idx) p_nh_master->nh_table_info_array[idx].p_update
     #define SYS_TBL_INFO_ID(idx) p_nh_master->nh_table_info_array[idx].table_id
     #define SYS_TBL_INFO_SIZE(idx) p_nh_master->nh_table_info_array[idx].entry_size
     #define SYS_TBL_INFO_OPF_DIR(idx) p_nh_master->nh_table_info_array[idx].alloc_dir

    if (DRV_FROM_AT(lchip))
    {
        sys_usw_nh_table_info_init_inner(lchip);/*init inner edit's table_id, p_func and p_func_unmap, no entry_size */
    }
    for (idx = SYS_NH_ENTRY_TYPE_NULL; idx < SYS_NH_ENTRY_TYPE_MAX; idx++)
    {
        switch(idx)
        {
        case SYS_NH_ENTRY_TYPE_FWD:
        case SYS_NH_ENTRY_TYPE_FWD_HALF:
            SYS_TBL_INFO_ID(idx)   = DsFwd_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsfwd;
            SYS_TBL_INFO_FUNC_UPDATE(idx)  =  (sys_usw_nh_update) sys_usw_nh_update_fwd;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsfwd;
            break;

        case SYS_NH_ENTRY_TYPE_FWD1:
        case SYS_NH_ENTRY_TYPE_FWD_HALF1:
            SYS_TBL_INFO_ID(idx)   = DsFwd1_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsfwd;
            SYS_TBL_INFO_FUNC_UPDATE(idx)  =  (sys_usw_nh_update) sys_usw_nh_update_fwd;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsfwd;
            break;

        case SYS_NH_ENTRY_TYPE_NEXTHOP_4W:
            SYS_TBL_INFO_ID(idx)   = DsNextHop4W_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsnexthop;
            SYS_TBL_INFO_FUNC_UPDATE(idx)  =  (sys_usw_nh_update) sys_usw_nh_update_dsnexthop_4w;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsnexthop;
            break;

        case SYS_NH_ENTRY_TYPE_NEXTHOP_8W:

            SYS_TBL_INFO_ID(idx)   = DsNextHop8W_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsnexthop;
            SYS_TBL_INFO_FUNC_UPDATE(idx)  =  (sys_usw_nh_update) sys_usw_nh_update_dsnexthop;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsnexthop;
            break;

        case SYS_NH_ENTRY_TYPE_NEXTHOP_INTERNAL:
            SYS_TBL_INFO_ID(idx)   = EpeNextHopInternal_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsnexthop;
            break;

        case SYS_NH_ENTRY_TYPE_MET:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_AT(lchip)?DsMetVector1X_t : DsMetEntry3W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_AT(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_met:
                                                                                          (sys_usw_nh_fun) sys_usw_nh_map_dsmet;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  DRV_FROM_AT(lchip)?(sys_usw_nh_fun_unmap) sys_usw_nh_unmap_met:
                                                                                          (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsmet;
            break;

        case SYS_NH_ENTRY_TYPE_MET_6W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_AT(lchip)?DsMetVector2X_t : DsMetEntry6W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_AT(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_met:
                                                                                          (sys_usw_nh_fun) sys_usw_nh_map_dsmet;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  DRV_FROM_AT(lchip)?(sys_usw_nh_fun_unmap) sys_usw_nh_unmap_met:
                                                                                          (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsmet;
            break;
        case SYS_NH_ENTRY_TYPE_MET_12W:
            SYS_TBL_INFO_ID(idx)   = DsMetVector4X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_met;
            SYS_TBL_INFO_FUNC_UNMAP(idx)   =  (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_met;
            break;

        /* +++ individual edit memory start +++ */
        case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W:
        case SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W:
            SYS_TBL_INFO_ID(idx)   = DsL2Edit6WOuter_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l2edit_addeth:
                                                                                   (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_eth;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l2edit_addeth:
                                                                                     (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsl2edit_eth;
            break;

        case SYS_NH_ENTRY_TYPE_L3EDIT_SPME:
            SYS_TBL_INFO_ID(idx)   = DsL3Edit6W3rd_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l3edit_addmpls_spme :
                                                                                    (sys_usw_nh_fun) sys_usw_nh_map_dsmpls_6w;
            break;
        /* +++ individual edit memory end +++ */

        /* +++ share edit memory start+++ */
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditAddMpls1X_t : DsL3EditMpls3W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l3edit_addmpls :
                                                                                    (sys_usw_nh_fun)sys_usw_nh_map_dsmpls;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS_2X:
            SYS_TBL_INFO_ID(idx)   = DsL3EditAddMpls2X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addmpls_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_MPLS_12W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditAddMpls4X_t : DsL3EditMpls12W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_l3edit_addmpls_sr:
                                                                                    (sys_usw_nh_fun)sys_usw_nh_map_dsmpls_12w;
            break;

        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditAddEth1X_t: DsL2EditEth3W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l2edit_addeth:
                                                                                    (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_eth;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l2edit_addeth:
                                                                                     (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsl2edit_eth;
            break;

        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditAddEth2X_t : DsL2EditEth6W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l2edit_addeth:
                                                                                    (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_eth;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l2edit_addeth:
                                                                                     (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsl2edit_eth;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW:
            SYS_TBL_INFO_ID(idx)   = DsL2EditAutoEth1X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_inner_autoeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l2edit_inner_autoeth;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W_RW:
            SYS_TBL_INFO_ID(idx)   = DsL2EditAutoEth2X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l2edit_inner_autoeth;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l2edit_inner_autoeth;
            break;

        case SYS_NH_ENTRY_TYPE_L2EDIT_FLEX_8W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditGemPort_t: DsL2EditFlex_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_l2edit_gemport:
                                                                                      (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_flex;
            break;

        case SYS_NH_ENTRY_TYPE_L2EDIT_INNER_SWAP:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditRwEth1X_t : DsL2EditInnerSwap_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_inner_swap;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_dsl2edit_inner_swap;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_SWAP:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditRwEth2X_t : DsL2EditSwap_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_l2edit_rweth2x :
                                                                                     (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_swap;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_OF_6W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditRwEth2X_t: DsL2EditOf_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun) sys_usw_nh_map_l2edit_rweth2x :
                                                                                    (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_of6w;
            break;
        case SYS_NH_ENTRY_TYPE_L2EDIT_LPBK:
            SYS_TBL_INFO_ID(idx)   = DsL2EditLoopback_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsl2edit_loopback;
            break;

        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V4:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditAddIp4_t: DsL3EditTunnelV4_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun)sys_usw_nh_map_l3edit_addip4:
                                                                                     (sys_usw_nh_fun) sys_usw_nh_map_tunnelv4;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)?(sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_addip4:
                                                                                     (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_tunnelv4;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V4_4X:
            SYS_TBL_INFO_ID(idx)   = DsL3EditAddIp44X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addip4;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addip4;
            break;

        case SYS_NH_ENTRY_TYPE_L3EDIT_TUNNEL_V6:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditAddIp6_t: DsL3EditTunnelV6_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun)sys_usw_nh_map_l3edit_addip6:
                                                                                      (sys_usw_nh_fun) sys_usw_nh_map_tunnelv6;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_addip6:
                                                                                      (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_tunnelv6;
            break;

        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_4W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditRwIp41X_t : DsL3EditNat3W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip41x_nat:
                                                                                    (sys_usw_nh_fun) sys_usw_nh_map_nat4w;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip41x_nat:
                                                                                    (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_nat4w;
            SYS_TBL_INFO_OPF_DIR(idx) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_8W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditRwIp4_t : DsL3EditNat6W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip4_nat:
                                                                                       (sys_usw_nh_fun) sys_usw_nh_map_nat8w;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip4_nat:
                                                                                       (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_nat8w;
            SYS_TBL_INFO_OPF_DIR(idx) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_V6_8W:
            SYS_TBL_INFO_ID(idx)   = DsL3EditRwIp62X_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip6_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip6_nat;
            SYS_TBL_INFO_OPF_DIR(idx) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_NAT_V6_16W:
            SYS_TBL_INFO_ID(idx)   = DsL3EditRwIp6_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_rwip6_nat;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_l3edit_rwip6_nat;
            SYS_TBL_INFO_OPF_DIR(idx) = 1;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_ADD_SRV6:
            SYS_TBL_INFO_ID(idx)   = DsL3EditAddIp6Sr_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addip6_sr;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addip6_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_RW_SRV6:
            SYS_TBL_INFO_ID(idx)   = DsL3EditRwIp6Sr_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip6_sr;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_rwip6_sr;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_SRH:
            SYS_TBL_INFO_ID(idx)   = DsL3EditAddIp6ExtHeader_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_srh;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_OF_6W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditRwIp4_t : DsL3EditOf6W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip4 :
                                                                                      (sys_usw_nh_fun) sys_usw_nh_map_dsl3edit_of6w;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_OF_12W:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditRwIp6_t : DsL3EditOf12W_t;
            SYS_TBL_INFO_FUNC(idx) = DRV_FROM_TMM(lchip)? (sys_usw_nh_fun) sys_usw_nh_map_l3edit_rwip6 :
                                                                                      (sys_usw_nh_fun) sys_usw_nh_map_dsl3edit_of12w;
            break;
       case SYS_NH_ENTRY_TYPE_L3EDIT_TRILL:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL3EditAddTrill_t : DsL3EditTrill_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_trill;
            break;
       case SYS_NH_ENTRY_TYPE_L3EDIT_LPBK:
            SYS_TBL_INFO_ID(idx)   = DsL3EditLoopback_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_dsl3edit_loopback;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_ADD_RAW:
            SYS_TBL_INFO_ID(idx)   = DsL3EditAddRaw_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_l3edit_addraw;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_l3edit_addraw;
            break;
        case SYS_NH_ENTRY_TYPE_L3EDIT_FP:
            SYS_TBL_INFO_ID(idx)   = DsL3EditRwFlex_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_fp;
            break;
        /* +++ share edit memory end +++ */

        case SYS_NH_ENTRY_TYPE_ECMP_GROUP:
            SYS_TBL_INFO_ID(idx)   = DsEcmpGroup_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_ecmp_group;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap)sys_usw_nh_map_unecmp_group;
            break;

        case SYS_NH_ENTRY_TYPE_ECMP_MEMBER:
            SYS_TBL_INFO_ID(idx)   = DsEcmpMember_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_ecmp_member;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_ecmp_member;
            break;

        case SYS_NH_ENTRY_TYPE_ECMP_RR_COUNT:
            SYS_TBL_INFO_ID(idx)   = DsEcmpRrCount_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_ecmp_rr_count;
            break;
       case SYS_NH_ENTRY_TYPE_L2EDIT_VLAN_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DRV_FROM_TMM(lchip)? DsL2EditRwEthVlanActionProfile_t : DsOfEditVlanActionProfile_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;
        case SYS_NH_ENTRY_TYPE_FP_ALU_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsL3EditFlexAluProfile_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;
        case SYS_NH_ENTRY_TYPE_FP_DATA_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsFlexEditInsertHeaderTemplate_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;

        case SYS_NH_ENTRY_TYPE_FP_L3CHKSUM_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsPktRwL3ChkSumMaskProfile_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;

        case SYS_NH_ENTRY_TYPE_FP_L4CHKSUM_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsPktRwL4ChkSumMaskProfile_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;
#if defined(ARCTIC)
        case SYS_NH_ENTRY_TYPE_XFP_EDIT:
            SYS_TBL_INFO_ID(idx)   = DsXEditRwFlex_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun)sys_usw_nh_map_l3edit_fp;
            break;
        case SYS_NH_ENTRY_TYPE_XFP_ALU_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsXEditFlexAluProfile_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;
        case SYS_NH_ENTRY_TYPE_XFP_DATA_PROFILE:
            SYS_TBL_INFO_ID(idx)   = DsXEditInsertHeaderTemplate_t;
            SYS_TBL_INFO_FUNC(idx) = NULL;
            break;
#endif
        case SYS_NH_ENTRY_TYPE_LOGIC_DEST_PORT:
            SYS_TBL_INFO_ID(idx)   = DsEgressLogicDestPort_t;
            SYS_TBL_INFO_FUNC(idx) = (sys_usw_nh_fun) sys_usw_nh_map_logic_dest_port;
            SYS_TBL_INFO_FUNC_UNMAP(idx) = (sys_usw_nh_fun_unmap) sys_usw_nh_unmap_logic_dest_port;
            break;

        default:
            break;

        }

        CTC_ERROR_RETURN(sys_usw_ftm_query_table_entry_size(lchip, SYS_TBL_INFO_ID(idx), &entry_size));


        if ((idx == SYS_NH_ENTRY_TYPE_DESTMAP_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_FP_ALU_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_FP_DATA_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_FP_L3CHKSUM_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_FP_L4CHKSUM_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_XFP_ALU_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_XFP_DATA_PROFILE)
            || (idx == SYS_NH_ENTRY_TYPE_L3EDIT_SPME)
            || (idx == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W)
            || (idx == SYS_NH_ENTRY_TYPE_LOGIC_DEST_PORT_EXT))
        {
            SYS_TBL_INFO_SIZE(idx) = 1;
        }
        else if(idx == SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W)
        {
            SYS_TBL_INFO_SIZE(idx) = 2;
        }
        else if((idx == SYS_NH_ENTRY_TYPE_FWD)||(idx == SYS_NH_ENTRY_TYPE_FWD1))
        {
            SYS_TBL_INFO_SIZE(idx) = 2;
        }
        else if ((idx == SYS_NH_ENTRY_TYPE_FWD_HALF)||(idx == SYS_NH_ENTRY_TYPE_FWD_HALF1))
        {
            SYS_TBL_INFO_SIZE(idx) = 1;
        }
        else
        {
            SYS_TBL_INFO_SIZE(idx) = DRV_FROM_TMM(lchip)? (entry_size / 16) : (entry_size / 12);
        }

        if (DRV_FROM_AT(lchip))
        {
            if ((idx == SYS_NH_ENTRY_TYPE_MET)
                || (idx == SYS_NH_ENTRY_TYPE_MET_6W)
            || (idx == SYS_NH_ENTRY_TYPE_MET_12W)
            || (idx == SYS_NH_ENTRY_TYPE_MET_RSVED))
            {
                SYS_TBL_INFO_SIZE(idx) = entry_size / 20;
            }
            if ((idx >= SYS_NH_ENTRY_TYPE_L2EDIT_FROM) && (idx <= SYS_NH_ENTRY_TYPE_L3EDIT_TO))
            {
                SYS_TBL_INFO_SIZE(idx + SYS_NH_TYPE_STEP_TO_INNER) = SYS_TBL_INFO_SIZE(idx);
            }
        }

    }

    if (DRV_FROM_TMM(lchip))
    {
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH1X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH2X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH2X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W_RW] = DRV_ENUM(DRV_L2EDITTYPE_AUTOETH2X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH1X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW] = DRV_ENUM(DRV_L2EDITTYPE_AUTOETH1X);
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_SWAP] = DRV_ENUM(DRV_L2EDITTYPE_RWETH1X);
        if(DRV_FROM_AT(lchip))
        {
            g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W + SYS_NH_TYPE_STEP_TO_INNER] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH2X);
            g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W_RW + SYS_NH_TYPE_STEP_TO_INNER] = DRV_ENUM(DRV_L2EDITTYPE_AUTOETH2X);
            g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W + SYS_NH_TYPE_STEP_TO_INNER] = DRV_ENUM(DRV_L2EDITTYPE_ADDETH1X);
            g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW + SYS_NH_TYPE_STEP_TO_INNER] = DRV_ENUM(DRV_L2EDITTYPE_AUTOETH1X);
            g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_SWAP + SYS_NH_TYPE_STEP_TO_INNER] = DRV_ENUM(DRV_L2EDITTYPE_RWETH1X);
        }
    }
    else
    {
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_4W] = SYS_NH_L2EDIT_TYPE_ETH_4W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_OUTER_8W] = SYS_NH_L2EDIT_TYPE_ETH_8W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W] = SYS_NH_L2EDIT_TYPE_ETH_8W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_6W_RW] = SYS_NH_L2EDIT_TYPE_ETH_8W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W] = SYS_NH_L2EDIT_TYPE_ETH_4W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW] = SYS_NH_L2EDIT_TYPE_ETH_4W;
        g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_SWAP] = SYS_NH_L2EDIT_TYPE_INNER_SWAP;
    }

    return CTC_E_NONE;

}

int32
sys_usw_nh_global_cfg_init(uint8 lchip)
{
    int32           cmd = 0;
    uint32          nh_offset = 0;
    uint32          field_value = 0;
    uint32 entry_num = 0;
    uint32 entry_num1 = 0;
    uint32          value = 0;
    ds_t  ds;
    sys_usw_nh_master_t* p_nh_master = g_usw_nh_master[lchip];
    sal_memset(ds, 0, sizeof(ds));
    cmd = DRV_IOR(MetFifoCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));
    SetMetFifoCtl(V, groupIdShiftBit_f, ds, g_usw_nh_master[lchip]->met_mode?1:0);    /*First met using 3w or 6w*/
    CTC_ERROR_RETURN(_sys_usw_nh_get_resolved_offset(lchip, SYS_NH_RES_OFFSET_TYPE_BRIDGE_NH, &nh_offset));
    SetMetFifoCtl(V, portBitmapNextHopPtr_f, ds, nh_offset);

    if (DRV_FROM_AT(lchip))
    {
        CTC_ERROR_RETURN(sys_usw_ftm_query_table_entry_num(lchip, DsMetEntry1X_t, &entry_num));
        SetMetFifoCtl(V, dsMetMemoryMax_f, ds, (entry_num >> 2));
        SetMetFifoCtl(V, metEntryPtrTail_f, ds, SYS_NH_MET_END_REPLICATE_OFFSET);
        if(g_usw_nh_master[lchip]->met_ext_mode)
        {
            SetMetFifoCtl(V, shareMetEn_f, ds, 1);
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET].p_func = (sys_usw_nh_fun)sys_usw_nh_map_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET].p_func_unmap = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET].table_id = DsMetVectorSlim1X_t;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_6W].p_func = (sys_usw_nh_fun)sys_usw_nh_map_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_6W].p_func_unmap = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_6W].table_id = DsMetVectorSlim2X_t;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_12W].p_func = (sys_usw_nh_fun)sys_usw_nh_map_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_12W].p_func_unmap = (sys_usw_nh_fun_unmap)sys_usw_nh_unmap_metslim;
            g_usw_nh_master[lchip]->nh_table_info_array[SYS_NH_ENTRY_TYPE_MET_12W].table_id = DsMetVectorSlim4X_t;
            CTC_ERROR_RETURN(sys_usw_ftm_query_table_entry_num(lchip, DsMetVectorSlim1X_t, &entry_num1));
            if (SYS_MET_MODE_EXT == g_usw_nh_master[lchip]->met_ext_mode)
            {
                SetMetFifoCtl(V, dsMetMemoryMax2_f, ds, ((entry_num + entry_num1) >> 2));
            }
        }
        else
        {
            SetMetFifoCtl(V, groupIdDefaultEntryMin_f, ds, 0);
            SetMetFifoCtl(V, groupIdDefaultEntryMax_f, ds, entry_num);
            SetMetFifoCtl(V, groupIdDefaultEntryShift_f, ds, g_usw_nh_master[lchip]->met_mode);
            SetMetFifoCtl(V, groupIdDefaultEntryBase_f, ds, 0);
        }
        SetMetFifoCtl(V, fitReplicationCtl_f, ds, (1 << 18) | nh_offset);
        SetMetFifoCtl(V, slimMetReplicationCtl_f, ds, (1 << 18) | nh_offset);
    }
    SetMetFifoCtl(V, checkDestMapOverflowEn_f, ds, 1);
    SetMetFifoCtl(V, minDestMap_f, ds, 0);
    sys_usw_ftm_query_table_entry_num(lchip, DsMetEntry3W_t, &value);
    SetMetFifoCtl(V, maxDestMap_f, ds, value-1);
    SetMetFifoCtl(V, checkDestMapOverFlowMode_f, ds, 0);
    cmd = DRV_IOW(MetFifoCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));

    /*AT..*/
    cmd = DRV_IOR(MetPreChkCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));
    SetMetPreChkCtl(V, checkDestMapOverflowEn_f,   &ds, 1);
    SetMetPreChkCtl(V, checkDestMapOverflowMode_f,   &ds, 0);
    SetMetPreChkCtl(V, mcastGrpIdMin_f,   &ds, 0);
    SetMetPreChkCtl(V, mcastGrpIdMax_f,   &ds, entry_num + entry_num1-1);
    cmd = DRV_IOW(MetPreChkCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));

    /*fatal exception*/
    sys_usw_nh_offset_alloc_with_multiple(lchip, SYS_NH_ENTRY_TYPE_FWD, 32, 32, &nh_offset);/*For AT, fatal exception use dsfwd0*/

    sal_memset(ds, 0, sizeof(ds));
    cmd = DRV_IOR(IpeDsFwdCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));
    SetIpeDsFwdCtl(V, dsFwdIndexBaseFatal_f, ds, (nh_offset >> 5));
    cmd = DRV_IOW(IpeDsFwdCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));
    p_nh_master->fatal_excp_base = nh_offset;

    sal_memset(ds, 0, sizeof(ds));
    cmd = DRV_IOR(IpeAclQosCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));
    SetIpeAclQosCtl(V, dsFwdIndexBaseFatal_f, ds, (nh_offset >> 5));
    cmd = DRV_IOW(IpeAclQosCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));

    cmd = DRV_IOR(IpeEcmpCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));
    /* enable dlb ipg */
    field_value = g_usw_nh_master[lchip]->h_ecmp_en?1:0;
    SetIpeEcmpCtl(V, hierarchicalEcmpEn_f, ds, field_value);
    if (DRV_FROM_AT(lchip))
    {   /*Vxlan 2 level ecmp*/
        SetIpeEcmpCtl(V, tunnelEcmpNewMode_f, ds, 1);
    }
    cmd = DRV_IOW(IpeEcmpCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, ds));

    cmd = DRV_IOW(EpeHdrAdjustCtl_t, EpeHdrAdjustCtl_dsNextHopInternalBase_f);
    CTC_ERROR_RETURN(DRV_FIELD_IOCTL(lchip, 0, cmd, &p_nh_master->internal_nexthop_base));

    /*if using cid 4w mode, nexthop stats function cannot used*/
    cmd = DRV_IOR(EpeNextHopCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));
    if (g_usw_nh_master[lchip]->cid_use_4w)
    {
        SetEpeNextHopCtl(V, categoryIdUse4W_f, &ds, 1);
    }
    SetEpeNextHopCtl(V, capwapBridgeOperation_f, &ds, 1);
    SetEpeNextHopCtl(V, innerEditPtrAdjEn_f, &ds, 1);
    SetEpeNextHopCtl(V, egressVlanStatsMode_f, &ds, 1);/*for support dstVlanStatsPtr */
    SetEpeNextHopCtl(V, snatEditPtrType_f, &ds, 1);
    SetEpeNextHopCtl(V, forceLogicDestPortGidEncode_f, &ds, 1); /*AT*/
    SetEpeNextHopCtl(V, apsMode_f, &ds, 1); /*AT*/
    cmd = DRV_IOW(EpeNextHopCtl_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));

    sal_memset(ds, 0, sizeof(ds));
    SetDsPktRwL4ChkSumMaskProfile(V, chksumMask_f, &ds, DRV_FROM_AT(lchip) ? 0xFFFFF : 0xFFFF0000);
    cmd = DRV_IOW(DsPktRwL4ChkSumMaskProfile_t, DRV_ENTRY_FLAG);
    CTC_ERROR_RETURN(DRV_IOCTL(lchip, SYS_L4CHKSUM_DISABLE_UPDATE_FOR_SRV6, cmd, &ds));

    if(DRV_FROM_TM(lchip))
    {
        /*init profile 0 for normal vxlan*/
        cmd = DRV_IOR(EpePktProcVxlanRsvCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));
        SetEpePktProcVxlanRsvCtl(V, g_0_udpDestPort_f, &ds, 4789);
        SetEpePktProcVxlanRsvCtl(V, g_0_vxlanFlags_f, &ds, 0x08);
        SetEpePktProcVxlanRsvCtl(V, gVxlanRsvField_0_vxlanFlags_f, &ds, 0x08);
        cmd = DRV_IOW(EpePktProcVxlanRsvCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &ds));

        p_nh_master->vxlan_edit_profile->udp_dest_port = DRV_FROM_TMM(lchip) ? 4789:0;
        p_nh_master->vxlan_edit_profile->flags = 0x08;
        p_nh_master->vxlan_edit_profile->ref_cnt = 0xFFFFFF;
    }

    if (DRV_FROM_TMM(lchip) && (CTC_WB_STATUS(lchip) != CTC_WB_STATUS_RELOADING) && !g_usw_nh_master[lchip]->rsv_l2edit_ptr)
    {
        DsL2EditAutoEth1X_m   dsl2edit3w;
        /*alloc l2edit reource for ipmc not CompateMode use*/
        CTC_ERROR_RETURN(sys_usw_nh_offset_alloc(lchip, SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW, 1, &g_usw_nh_master[lchip]->rsv_l2edit_ptr));
        sal_memset(&dsl2edit3w, 0, sizeof(dsl2edit3w));
        SetDsL2EditAutoEth1X(V,deriveMcastMacForIp_f,&dsl2edit3w,1);
        SetDsL2EditAutoEth1X(V,macDaRewriteEn_f,&dsl2edit3w,1);
        SetDsL2EditAutoEth1X(V,macSaRewriteEn_f,&dsl2edit3w,1);
        SetDsL2EditAutoEth1X(V,interfaceVlanEn_f,&dsl2edit3w,1);
        SetDsL2EditAutoEth1X(V, dsType_f, &dsl2edit3w,  SYS_NH_DS_TYPE_L2EDIT);
        SetDsL2EditAutoEth1X(V, l2EditType_f,  &dsl2edit3w, g_usw_nh_master[lchip]->rewrite_type[SYS_NH_ENTRY_TYPE_L2EDIT_INNER_3W_RW]);
        cmd = DRV_IOW(DsL2EditAddEth1X_t, DRV_ENTRY_FLAG);
        DRV_IOCTL(lchip, g_usw_nh_master[lchip]->rsv_l2edit_ptr, cmd, &dsl2edit3w);
    }

    if (DRV_FROM_AT(lchip))
    {
        uint32 chk_min = 0;
        uint32 chk_max = 0x3FFFF;
        uint32 xlate_min = 0;
        uint32 xlate_max = 0;

        /*VxLAN LogicPortExt , which used for editAuxData*/
        sal_memset(ds, 0, sizeof(ds));
        cmd = DRV_IOR(IpeFwdCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));
        SetIpeFwdCtl(V, ecmpTunnelModeFieldMode_f, &ds, 0x1);
        SetIpeFwdCtl(V, editAuxDataHighBits_f, &ds, 0x2);
        cmd = DRV_IOW(IpeFwdCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));

        CTC_ERROR_RETURN(sys_usw_ftm_query_table_entry_num(lchip, DsNextHopIdMapPointer_t, &entry_num));
        if (entry_num)
        {
            xlate_min = 256*1024 - (entry_num*SYS_NH_MAP_UNIT_SIZE);
            xlate_max = 256*1024 - 1;
            g_usw_nh_master[lchip]->nh_mapper_base = xlate_min;

            value = 0;
            cmd = DRV_IOW(EpeHdrAdjustCtl_t, EpeHdrAdjustCtl_bypassPopNhpIdToPointerTable_f);
            CTC_ERROR_RETURN(DRV_FIELD_IOCTL(lchip, 0, cmd, &value));
        }

        sal_memset(ds, 0, sizeof(ds));
        cmd = DRV_IOR(EpeHdrAdjNextHopPtrXlateCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));
        g_usw_nh_master[lchip]->nh_mapper_num = entry_num;
        SetEpeHdrAdjNextHopPtrXlateCtl(V, gXlate_0_nextHopPtr_f, &ds, xlate_min);
        SetEpeHdrAdjNextHopPtrXlateCtl(V, gXlate_1_nextHopPtr_f, &ds, xlate_max);
        SetEpeHdrAdjNextHopPtrXlateCtl(V, gChk_0_nextHopPtr_f, &ds, chk_min);
        SetEpeHdrAdjNextHopPtrXlateCtl(V, gChk_1_nextHopPtr_f, &ds, chk_max);
        cmd = DRV_IOW(EpeHdrAdjNextHopPtrXlateCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));

        sal_memset(ds, 0, sizeof(ds));
        cmd = DRV_IOR(NextHopPointerXlateCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));
        if (entry_num == 16*1024)/*memory401, 16K*440bits */
        {
            SetNextHopPointerXlateCtl(V, gMemCfg_0_memEn_f, &ds, 1);
            SetNextHopPointerXlateCtl(V, gMemCfg_0_memMinIndex_f, &ds, 0);
            SetNextHopPointerXlateCtl(V, gMemCfg_0_memMaxIndex_f, &ds, entry_num*SYS_NH_MAP_UNIT_SIZE - 1);
        }
        else if (entry_num == 4*1024)/*memory404 or memory405, 4K*440bits */
        {
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memEn_f, &ds, 1);
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memMinIndex_f, &ds, 0);
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memMaxIndex_f, &ds, entry_num*SYS_NH_MAP_UNIT_SIZE - 1);
        }
        else if (entry_num == 8*1024)/*memory404 and memory405, (4K+4K)*440bits*/
        {
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memEn_f, &ds, 1);
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memMinIndex_f, &ds, 0);
            SetNextHopPointerXlateCtl(V, gMemCfg_1_memMaxIndex_f, &ds, (4*1024*SYS_NH_MAP_UNIT_SIZE - 1));

            SetNextHopPointerXlateCtl(V, gMemCfg_2_memEn_f, &ds, 1);
            SetNextHopPointerXlateCtl(V, gMemCfg_2_memIndexBase_f, &ds, 4*1024);
            SetNextHopPointerXlateCtl(V, gMemCfg_2_memMinIndex_f, &ds, 4*1024*SYS_NH_MAP_UNIT_SIZE);
            SetNextHopPointerXlateCtl(V, gMemCfg_2_memMaxIndex_f, &ds, entry_num*SYS_NH_MAP_UNIT_SIZE - 1);
        }
        SetNextHopPointerXlateCtl(V, nextHopPtrXlateBase_f, &ds, g_usw_nh_master[lchip]->nh_mapper_base);
        cmd = DRV_IOW(NextHopPointerXlateCtl_t, DRV_ENTRY_FLAG);
        CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0 , cmd, &ds));


        /*TBD need to call xdata api to alloc profile, now force use profile 1*/
        {
            /* EpeHdrAdjustXCtl */
            EpeHdrAdjustXCtl_m epehdr_xctl;
            MetFifoXCtl_m metfifo_xctl;
            PreBufferRetrieveXCtl_m prebufretrive_xctl;

            cmd = DRV_IOR(EpeHdrAdjustXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &epehdr_xctl));
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibbleEn_8_nibbleEn_f, &epehdr_xctl, 1);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibbleEn_9_nibbleEn_f, &epehdr_xctl, 1);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibbleEn_10_nibbleEn_f, &epehdr_xctl, 1);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibbleEn_11_nibbleEn_f, &epehdr_xctl, 1);

            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibble_8_destNibble_f, &epehdr_xctl, 0);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibble_9_destNibble_f, &epehdr_xctl, 1);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibble_10_destNibble_f, &epehdr_xctl, 2);
            SetEpeHdrAdjustXCtl(V, gXHeader_1_profile_gSrcNibble_11_destNibble_f, &epehdr_xctl, 3);
            cmd = DRV_IOW(EpeHdrAdjustXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &epehdr_xctl));

            cmd = DRV_IOR(MetFifoXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &metfifo_xctl));
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibbleEn_0_nibbleEn_f, &metfifo_xctl, 1);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibbleEn_1_nibbleEn_f, &metfifo_xctl, 1);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibbleEn_2_nibbleEn_f, &metfifo_xctl, 1);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibbleEn_3_nibbleEn_f, &metfifo_xctl, 1);

            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibble_0_srcNibble_f, &metfifo_xctl, 0);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibble_1_srcNibble_f, &metfifo_xctl, 1);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibble_2_srcNibble_f, &metfifo_xctl, 2);
            SetMetFifoXCtl(V, gXHeaderExt_1_profile_gDestNibble_3_srcNibble_f, &metfifo_xctl, 3);
            cmd = DRV_IOW(MetFifoXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &metfifo_xctl));

            cmd = DRV_IOR(PreBufferRetrieveXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &prebufretrive_xctl));
            SetPreBufferRetrieveXCtl(V, gXHeader_1_nibbleEn_f, &prebufretrive_xctl, 0xF);
            SetPreBufferRetrieveXCtl(V, xHeaderTypeEn_f, &prebufretrive_xctl, 0x2);
            cmd = DRV_IOW(PreBufferRetrieveXCtl_t, DRV_ENTRY_FLAG);
            CTC_ERROR_RETURN(DRV_IOCTL(lchip, 0, cmd, &prebufretrive_xctl));
        }
    }
    return CTC_E_NONE;
}






